Reputation: 525
I am trying to read command line arguments in bash but I have problems to read on the 10th column. Here is my sample script:
#-------------------------------------------------------
#!/bin/bash
an=$2 mn=$4 dy=$6 der=$8 new=$10 sec=(${12} ${13})
echo $an $mn $dy $der $new $sec
#--------------------------------------------------------
I have run the above script "test.sh" as
./test.sh -yr cat -mn Jan -dy tuesday -der tt -new car -sec 001 001
The output is:
cat Jan tuesday tt -yr0 001
But for variable $new ($10) the answer should have been car
but I get -yr0
Any idea why?
Upvotes: 2
Views: 783
Reputation: 40688
Here is the fix:
#!/bin/bash
an=$2 mn=$4 dy=$6 der=$8 new=${10} sec="${12} ${13}"
echo $an $mn $dy $der $new $sec
Upvotes: 3
Reputation: 3688
new=$10
is giving you $1
(i.e 'yr') appended with 0
. You need some braces : ${10}
Upvotes: 4