jculkincys
asked on
bash dynamic variable assignment
I need to assign values to dynamic variables
EX "$time"ofpurchase=$var
andy tips?
I keep getting "command not found error"
thanks
jculkincys
EX "$time"ofpurchase=$var
andy tips?
I keep getting "command not found error"
thanks
jculkincys
help eval
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I almost got it
I just need a little more hand holding
I have dyname name on each side of the equation
eval "$time"_u_staff=$staff # doesnt work
I am trying to get more info
does the above help at all?
I just need a little more hand holding
I have dyname name on each side of the equation
eval "$time"_u_staff=$staff # doesnt work
I am trying to get more info
does the above help at all?
in order to better separate your bash variables, the preferred method is
eval ${time}_u_staff=${staff}
eval ${time}_u_staff=${staff}
ASKER
Hmm I am stil getting errors
Portion of Code:
eval ${time}_u_faculty=${facult y}
echo "${time}_u_faculty --> $(${time}_u_faculty)"
Output of script with set -xv:
+ eval 00_u_faculty=0
00_u_faculty=0
++ 00_u_faculty=0
./analyzelogsdev.sh: 00_u_faculty=0: command not found
Portion of Code:
eval ${time}_u_faculty=${facult
echo "${time}_u_faculty --> $(${time}_u_faculty)"
Output of script with set -xv:
+ eval 00_u_faculty=0
00_u_faculty=0
++ 00_u_faculty=0
./analyzelogsdev.sh: 00_u_faculty=0: command not found
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help
any tips on reading a dynamic variable?
for example while in a for loop I want to pull all the values back
Ex.
for time in 1 2 3
do
echo ${u_faculty_${time}}
done
I am stuck with the following
+ time=01
echo `\${u_staff_${time}}`
${u_staff_${time}}
./analyzelogsdev.sh: ${u_staff_${time}}: bad substitution
++ echo
+ echo 'PLEASE WORK: '
PLEASE WORK:
+ exit 0
any tips on reading a dynamic variable?
for example while in a for loop I want to pull all the values back
Ex.
for time in 1 2 3
do
echo ${u_faculty_${time}}
done
I am stuck with the following
+ time=01
echo `\${u_staff_${time}}`
${u_staff_${time}}
./analyzelogsdev.sh: ${u_staff_${time}}: bad substitution
++ echo
+ echo 'PLEASE WORK: '
PLEASE WORK:
+ exit 0
you cannot use embedded braces {}, use this syntax:
eval echo "\$u_faculty_${time}"
eval echo "\$u_faculty_${time}"