Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8151485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:24:19+00:00 2026-06-06T15:24:19+00:00

So I have a bash script that needs to take an arbitrary number of

  • 0

So I have a bash script that needs to take an arbitrary number of command line arguments and put them into a single string

Example of what the user would type in:

give <environment> <email> <any number of integers separated by spaces>
give testing stuff@things.com 1 2 3 4 5

I want to get all of the arguments from $3 to $# and concat them into a string.

My (probably awful) solution right now is

if [ $# -gt 3 ]
then
    env="env="$1
    email="email="$2
    entList=""

    for i in {3..$#}
    do
        if [ $i -eq 3 ]
            then
                    entList=$3
                    shift
            fi;
            if [ $i -gt 3 ]
            then
                    entList=$entList","$3
                   shift
            fi;
     done
fi;

I handle the case of having only three arguments a bit differently, and that one works fine.

Final value of $entList given the example give testing stuff@things.com 1 2 3 4 5 should be: 1,2,3,4,5

Right now when i run this i get the following Errors:

/usr/local/bin/ngive.sh: line 29: [: {3..5}: integer expression expected
/usr/local/bin/ngive.sh: line 34: [: {3..5}: integer expression expected

Lines 29 and 34 are:

line 29: if [ $i -eq 3 ]
line 34: if [ $i -gt 3 ]

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:24:22+00:00Added an answer on June 6, 2026 at 3:24 pm

    You’re on the right track. Here’s my suggestion:

    if [ $# -ge 3 ]; then
    
      env="$1"
      email="$2"
      entlist="$3"
    
      while shift && [ -n "$3" ]; do
        entlist="${entlist},$3"
      done
    
      echo "entlist=$entlist"
    
    else
    
      echo "Arguments: $*"
    
    fi
    

    Note that variables should always be put inside quotes. I’m not sure why you were setting env=env=$1, but I suspect that if you want to recycle that value later, you should do it programatically rather than by evaluating the variable as if it were a statement, in case that was your plan.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a bash script that needs to take a single line
I have a Python3 script that can take optional command line parameters which the
I have a bash script that needs to perform a couple actions in MySQL.
I have a script in Bash called Script.sh that needs to know its own
I have a bash script that runs (something like) the following command: vim -E
I have a sh/bash script that needs to call a batch file with parameters
I have written a little bash script that reads commands (one per line), in
I've got a bash script that can take arguments in a variety of different
I have a bash script that needs to build some sets each containing 1
I have a bash script that I need to write my password to run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.