Reputation: 7794
Essentially I have a script which acts as a task wrapper and emails a user if the task fails.
The task is passed in as an argument to the script. The problem comes when we need to run multiple commands say the following line is passed to the script as the task arg "echo this; echo that"
would output this; echo that.
So the question is what is the easiest way to run multiple commands without having to loop through the input command string and split on the ';' char?
Simple example:
FIRST=$1
TASK=$*
echo run
echo "emailing $FIRST"
$TASK
echo done
and to run this script we would use ./wrapper.sh "[email protected]" "echo this; echo that"
Suggestions?
Upvotes: 1
Views: 3144
Reputation: 104080
If you execute the string $TASK
via sh -c
, you might not need to do any more work:
$ sh -c "echo this ; echo that"
this
that
$
Upvotes: 7