I want to write a bash function that executes an arbitrary commands on multiple branches.
compare_command () {
branch2="$1"
shift
command="$@"
echo $branch2
echo $command
# assume $@ is command and args
$(command) 2>&1 | tee baseline.log
git checkout "$branch2"
$(command) 2>&1 | tee "$branch2".log
git checkout -
}
compare_command master ls
, for example, fails with "command not found: 1"
compare_command master ls -a
, fails with "command not found: ls -a"
"$@"
to a string and then use it as a command. Also,$(command)
runs thecommand
built-in command and nothing else. As muru says, you don't appear to be running the code you are showing. – Kusalananda Dec 29 '20 at 17:15$(command "$args")
or some such? – Sam Shleifer Dec 29 '20 at 17:20