I am writing a bash script and I would like to be able to store each command line argument as it's own variable. So if there was a command line like so:
./myscript.sh word anotherWord yetAnotherWord
The result should be:
variable1 = word
variable2 = anotherWord
variable3 = yetAnotherWord
I have tried using a for loop and $@ like so:
declare -A myarray
counter=0
for arg in "$@"
do
myarray[$counter]=arg
done
but when i try to echo say variable1 i get arg[1] instead of the expected word
any help would be appreciated.
foo=([0]=a [5]=b [13]=c)is legal.argis a regular string;$argis the value of the parameter namedarg. You also appear to be writing$myarray[1]rather than${myarry[1]}.