Reputation: 47296
I have script file where a command is stored in a variable
First i got the command (assume "ls -l " command)
cmd=`cat /proc/2345/cmdline`
now doing
echo $cmd
outputs
ls -l
Now how to use $cmd to actually execute that command. which is ls -l
Upvotes: 0
Views: 244
Reputation: 172448
eval $cmd
Just $cmd
will work in many cases, but not always. See the article "Bash: Why use eval with variable expansion?" for further details.
Upvotes: 3
Reputation: 342969
if you have no business to store it in a variable, then don't. Just run it as usual.
cat /proc/2345/cmdline
Upvotes: 2