OK, this one is doing my head in X-)
I want to pass (possible) multiple commands to a script, for it to execute. I'm using an option/value syntax :- "-c "command ; command ; command" to set a variable which I then try to execute later on.
Unfortunately, only the 1st command in the string is run & the rest are ignored. I've tried the following test to see what's happening :-
which results in :-
so, issuing command ; command works OK,
issuing $cmd just runs the 1st command &
issuing `$cmd` runs the 1st command & generates an error msg :-0
Any ideas/hint/tips on this? TandA
Day by day, the penguins steal my sanity.
I want to pass (possible) multiple commands to a script, for it to execute. I'm using an option/value syntax :- "-c "command ; command ; command" to set a variable which I then try to execute later on.
Unfortunately, only the 1st command in the string is run & the rest are ignored. I've tried the following test to see what's happening :-
Code:
# cat test
#!/bin/sh
cmd="pwd ; uname -a"
pwd ; uname -a
$cmd
`$cmd`
Code:
# sh -vx ./test
#!/bin/sh
cmd="pwd ; uname -a"
cmd=pwd ; uname -a
pwd ; uname -a
+ pwd
/usr/local/bin/sysadm
+ uname -a
SunOS ncwcs36 5.5.1 Generic_103640-31 sun4d sparc SUNW,SPARCserver-1000
$cmd
+ pwd ; uname -a
/usr/local/bin/sysadm
`$cmd`
+ pwd ; uname -a
+ /usr/local/bin/sysadm
./test: /usr/local/bin/sysadm: cannot execute
issuing $cmd just runs the 1st command &
issuing `$cmd` runs the 1st command & generates an error msg :-0
Any ideas/hint/tips on this? TandA
Day by day, the penguins steal my sanity.