executing a variable assignment in a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting executing a variable assignment in a string
# 1  
Old 06-01-2010
executing a variable assignment in a string

I'm using whatever the scripting is in this copy of busybox ! So not the full boxed set sometimes.


If I do

cmd="echo fred"
$cmd

the system prints "fred"

if I do

cmd="fred=9"
$cmd

it barfs.

Is there a simple way to put a varabble assignment in a string and execute it?

David
# 2  
Old 06-01-2010
Try:

Code:
cmd="fred=999"
eval $cmd
echo $fred

This User Gave Thanks to dennis.jacob For This Post:
# 3  
Old 06-01-2010
Thanks

I knew I'd seen it done somewhere.... just couldn't google how!

TVM
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable Assignment

Hi I am facing a problem. export local_folder=/opt/app/ cd /opt/app/abc/ abcversion="abc*" (abcga5 is inside /opt/app/abc/) echo $abcversion (it echoes the correct version as abcga5 ) Now when I reuse the value of abcversion for a below path: export... (6 Replies)
Discussion started by: ankur328
6 Replies

2. Shell Programming and Scripting

Same Variable Assignment

Hi I have a strange problem: In my shell script I am performing a copy task: . prop.txt cp -r $dir/ $dir/archive $dir is fetched from a property file (prop.txt) which stores its value dir=/opt/data Now the problem is another dir1 comes into picture. I only want to add... (1 Reply)
Discussion started by: ankur328
1 Replies

3. Shell Programming and Scripting

Usage of # in assignment of variable

guys, i would like to know what does the below does. tr=`echo $bfile | cut -d"." -f4` tr=${tr#TR} i tried with assigning a value and executed second line. but after that also value of tr remains same. thanks in advance .. (1 Reply)
Discussion started by: expert
1 Replies

4. Shell Programming and Scripting

Use one loop get the variable assignment

for var in {1..3} do lspci -nn |awk -v i=$var '/8086:10a7/{split($1,a,""); print "0x"a}' done it will output 0x01 0x00 0x1 I want to let bus=0x01 slot=0x00 fun=0x1, How to modify this loop? I know it can be get by bus=`lspci -nn |awk... (4 Replies)
Discussion started by: yanglei_fage
4 Replies

5. Shell Programming and Scripting

Complex variable assignment

Hi, I have a requirement as follows, need to call the format of ${$var} form. For example, i am taking a variable. count=1, ((LIMIT_$count=$count + 1)) Now i have to echo this variable LIMIT_$count. (This is in a loop..) echo ${LIMIT_$count} - displays as a syntax... (3 Replies)
Discussion started by: abhisheksunkari
3 Replies

6. Shell Programming and Scripting

Help with variable assignment

Hi, In AIX I have a variable with , (coma) separated values assigned to it like shown below var1=apple,boy,chris i want to convert this to var1='apple','boy','chris' the number of values assigned to var1 might change and it could be from 1 to n any suggestions please? (3 Replies)
Discussion started by: rahul9909
3 Replies

7. Shell Programming and Scripting

Executing a variable that strores a unix command string

Hi: I have a touble with executing a variable that stores a unix command string. The following would be excuted fine: command='ls -l' `echo $command` However, the following gives me an error: command='(uuencode file1 file1; uuencode file2 file2) | mailx email_id' `echo... (1 Reply)
Discussion started by: sagewise
1 Replies

8. Shell Programming and Scripting

Indirect variable assignment

Hi I have variable A_B=alpha also var1="A" var2="B" I want to retrieve the value alpha using var1 and var2 , somthing like echo ${${var1}_${var2}} that works. Obviously this is receiving syntax error (6 Replies)
Discussion started by: sumir
6 Replies

9. Shell Programming and Scripting

substituted variable assignment

I try to run this script, however, it gives an exception in line 3. How do I do an assignment to a substituted variable? #!/bin/bash name=fruit ext_$(eval echo ${name})=apple tmp=ext_$(eval echo ${name}) if ]; then echo "apple" elif ]; then echo "orange" fi echo ${!tmp} Error... (2 Replies)
Discussion started by: angelokh
2 Replies

10. UNIX for Dummies Questions & Answers

@ in a variable assignment

Hello Everybody, Does anyone know what the @ symbol means in a csh script, if used with a variable assignment as below @ line = 1 why not just use.... set line=1 Many thanks rkap (1 Reply)
Discussion started by: rkap
1 Replies
Login or Register to Ask a Question