bash save command before running
Imagine you want to save a command to a variable (maybe so you can echo it out) before running it.
There's nothing special about saving it to a variable. However, when you go to run the saved command you may end up with a headache if you don't use eval
.
If your command is simple it may work without eval
, but more complex commands will start to do strange things.
Use eval
!
CMD="curl -s http://google.com"
echo "$CMD"
RESULT=$(eval $CMD)
echo "$RESULT"