On Bash, I first define a variable CMD for a command line bash instruction, then I run it. An error occurs. Where does it go wrong?
$ CMD="VERBOSE=1 ./myscript"
$ $CMD
bash: VERBOSE=1: command not found
On Bash, I first define a variable CMD for a command line bash instruction, then I run it. An error occurs. Where does it go wrong?
$ CMD="VERBOSE=1 ./myscript"
$ $CMD
bash: VERBOSE=1: command not found
Don't store commands in variables. Variables aren't smart enough to hold commands. They will let you down time and time again like your roommate that never washes the dishes.
Use a function. They're the right tool for the job. You can use them like they were regular executables; they can take arguments; there are no quoting/backslash/whitespace issues.
$ cmd() {
> VERBOSE=1 ./myscript
> }
$ cmd
Functions are where it's at.
See also: