You are not logged in.
I've tried different combinations, of which all returns "command not found"
array$j[$n]=$f
array${j}[$n]=$f
"array${j}"[$n]=$f
etc...
What's the right syntax?
Thanks!:)
Last edited by zfsd (2010-02-20 23:02:54)
Offline
printf -v
--> arr[1]=4
--> q=r
--> printf -v ar$q[2] 5
--> echo ${arr[1]}
4
--> echo ${arr[2]}
5
Offline
Thanks, but the printf doesn't do anything for me.
Basically, I'm writing a script for concatenating a bunch of files.
I need to be able to set a variable in the name of the array for the script to work.
This is how I want the arrays to look:
./main.sh: line 84: job1[1]=1: command not found
./main.sh: line 68: job2[1]=2: command not found
./main.sh: line 68: job3[1]=3: command not found
./main.sh: line 68: job4[1]=4: command not found
./main.sh: line 68: job5[1]=5: command not found
./main.sh: line 68: job6[1]=6: command not found
./main.sh: line 68: job7[1]=7: command not found
./main.sh: line 68: job8[1]=8: command not found
./main.sh: line 68: job9[1]=9: command not found
./main.sh: line 84: job9[2]=10: command not found
./main.sh: line 68: job10[1]=11: command not found
./main.sh: line 68: job11[1]=12: command not found
./main.sh: line 84: job11[2]=13: command not found
./main.sh: line 68: job12[1]=14: command not found
./main.sh: line 84: job12[2]=15: command not found
./main.sh: line 84: job12[3]=16: command not found
./main.sh: line 84: job12[4]=17: command not found
./main.sh: line 84: job12[5]=18: command not found
./main.sh: line 84: job12[6]=19: command not found
./main.sh: line 84: job12[7]=20: command not found
./main.sh: line 84: job12[8]=21: command not found
But I'm using the wrong syntax..
Why isn't the syntax job$j[$f]=$n not working?
printf -v job$j[$f] $n is not working..
Offline
What about eval?
--> eval job$j[$f]=9
--> eval echo \${job$j[$f]}
9
Offline
FANTASTIC!
It works perfectly now!
So the eval concatenates the arguments and make it more readable?
Job 12
#####
14
15
16
17
18
19
20
21
Job 13
#####
22
23
Job 14
#####
24
25
26
27
28
Job 15
#####
29
30
31
Job 16
#####
32
Thanks again -- you saved my day
Offline
So the eval concatenates the arguments and make it more readable?
More or less. From the FreeBSD sh man page: Concatenate all the arguments with spaces. Then re-parse and execute the command.
And the bash man page: The args are read and concatenated together into a single command. This command is then read and executed by the shell, and its exit status is returned as the value of eval.
Happy coding.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
Indeed
Offline