Shellscript variable as command string
When I was trying form a command from different variables to one variable, I was successive.
echo "The command is: $CMD"
The command is: mount /dev/sdb /mnt/disk0
Error: No such file or directory:
Note: Both the /dev/sdb and /mnt/disk0 exists.
If I am running the same command without using variable from the script, it was working fine.
Please help me to get out of this problem.
seems to be a quoting issue. Can you try the following
The simple answer here is that you don't do it that way. Variables are for storing data, not code.
I'm trying to put a command in a variable, but the complex cases always fail!
Once a string is stored in a variable, the parsing rules for it are very different, and you just can't reliably run a complex command that way. If you want to set up a dynamic command of some kind, use a function.
I have wrote the command to a file and executed the file within the script.
|All times are GMT -5. The time now is 10:27 PM.|