It is currently Mon, 08 Aug 2022 20:39:11 GMT

Author Message
 Executing contents of variable in shell script

I have the following questing about shell scripting. I have a command with
several parameters divided by spaces and some of those parameters are
strings between quotes with spaces. For example:

command -parameter1 -parameter2 "value for parameter2" -parameter3 "value
for parameter3"

The number of parameters is not fixed. I fill them with a for-loop. I tried
a lot of things but my shell (Bash) does not substitute the way I want hem
to substitute my variables. First I tried to place te output of the
for-loop in a textfile and did the following command within my script:

command -parameter1 $(cat tempfile.txt)

$ cat tempfile.txt
-parameter2 "value for parameter2" -parameter3 "value for parameter3"

but when I execute the script I get the following error:
command: illegal option: for parameter2" or something like that. So the
shell breaks my command apart at the spaces.

So I tried to put the whole command in a variable so when I do an echo of
that variable it says:

echo $STRING
command -parameter1 -parameter2 "value for parameter2" -parameter3 "value
for parameter3"

but when I try to execute it by doing:
or "$STRING"
The shell keeps messing up with the spaces. So my question is: How can I
execute the contents of a variable?

Thanks in advance,


 Fri, 17 Jun 2005 01:50:08 GMT   
 Executing contents of variable in shell script

Try "eval"


 Fri, 17 Jun 2005 02:36:21 GMT   
 Executing contents of variable in shell script

Thanks that works! The beauty of Unix, you never stop learning! :-)


 Fri, 17 Jun 2005 20:10:35 GMT   
   [ 3 post ] 

Similar Threads

1. shell scripting: echoing contents of contents of variable

2. file contents into variable, or global variable from shell script

3. Executing a shell script to set env variables

4. How do i transfer the contents of shell variable to a variable used in C program

5. shell-script executes a perl-script???

6. Executing shell script from NT .BAT-script

7. executing script in shell-script

8. MST PPP: Trouble executing shell script from chat script for Secure ID.

9. a question about executing a shell script (c-shell)

10. executing 1 korn shell script from a 2nd script

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software