I was wondering: When I e.g. call
list=$(ps -ax)
is ps -ax executed once and I can read the value multiple times or is the command executed e
To cite the bash manpage:
Command Substitution
Command substitution allows the output of a com-
mand to replace the command name. There are two forms:
$(command)
or
`command`
So the output of the command is stored, not the command itself.
If you want to store a command that is evaluated each time, you need to use eval:
#!/bin/bash
command="date"
startTime=$(date)
for i in `seq 1 4`
do
echo "$i: $startTime - " $(eval $command)
sleep 1
done