store-command.md
01 Feb 2017 | bashStoring a command in a var to evaluate it whenever needed
# Store the cmd
CMD="wc -l a.txt"
touch a.txt
echo $CMD
# >> wc -l a.txt
# The result of the command is obtained using
echo `eval $CMD`
# >> 0 a.txt
echo "Hello !" >> a.txt
echo `eval $CMD`
# >> 1 a.txt
WARNING: in the terminal, $CMD
returns the result of the command, use echo $CMD
to get the command.
Comments