So I have a bash script that should take an arbitrary number of command line arguments and put them on one line
User input example:
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 arguments from $ 3 to $ # and combine them into a string.
My (possibly awful) solution now
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 little differently and this one works fine.
The final value $entListgiven in the example give testing stuff@things.com 1 2 3 4 5should 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:
line 29: if [ $i -eq 3 ]
line 34: if [ $i -gt 3 ]
Any help would be appreciated.
source
share