?
Solved

bash dynamic variable assignment

Posted on 2006-05-10
8
Medium Priority
?
1,201 Views
Last Modified: 2012-06-21
I need to assign values to dynamic variables

EX "$time"ofpurchase=$var

andy tips?

I keep getting "command not found error"

thanks
jculkincys
0
Comment
Question by:jculkincys
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 16653043
help eval
0
 
LVL 35

Assisted Solution

by:Duncan Roe
Duncan Roe earned 1000 total points
ID: 16653081
Here's an example:

07:15:40$ i=j
07:15:48$ j=foo
07:16:04$ k=bar
07:16:55$ eval $i=$k
07:17:16$ echo $j
bar
0
 
LVL 2

Author Comment

by:jculkincys
ID: 16653153
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?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 19

Expert Comment

by:Gabriel Orozco
ID: 16653418
in order to better separate your bash variables, the preferred method is

eval ${time}_u_staff=${staff}
0
 
LVL 2

Author Comment

by:jculkincys
ID: 16654061
Hmm I am stil getting errors

Portion of Code:

        eval ${time}_u_faculty=${faculty}
        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
0
 
LVL 27

Accepted Solution

by:
Nopius earned 1000 total points
ID: 16654505
variable name cannot start with a digit, so "00_u_faculty" is incorrect name.
   
0
 
LVL 2

Author Comment

by:jculkincys
ID: 16655336
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
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16655359
you cannot use embedded braces {}, use this syntax:

eval echo "\$u_faculty_${time}"
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question