In BASH, I want to do something like this:
#!/bin/bash
HOST="blah"
USER="foo"
REMOTE_ROOT="${HOST}:~${USER}/"
REP_NAME=`basename $1`
TARGET_NAME="${REP_NAME}.git"
CMD1="git clone --bare $1 $TARGET_NAME"
CMD2="touch ${TARGET_NAME}/git-daemon-export-ok"
CMD3="scp -r $TARGET_NAME $REMOTE_ROOT"
CMD4="rm -rf $TARGET_NAME"
for i in {1..4}
do
CMD="${CMD${i}}"
echo "$CMD"
`$CMD`
done
That is to say, I want to loop over a list of commands, display the command being executed, then execute it.
I don't know how to do the double dereferencing (CMD="${CMD${i}}" isn't legal in BASH).
Alternately, I'd be happy to do something like:
for CMD in "CMD1 CMD2 CMD3 CMD4"
do
echo $$CMD
done
but of course that isn't the right syntax, either.