I want to write code like this:
command=\"some command\"
safeRunCommand $command
safeRunCommand() {
cmnd=$1
$($cmnd)
if [ $? != 0 ]
It should be $cmd instead of $($cmd). Works fine with that on my box.
Edit: Your script works only for one-word commands, like ls. It will not work for "ls cpp". For this to work, replace cmd="$1"; $cmd with "$@". And, do not run your script as command="some cmd"; safeRun command, run it as safeRun some cmd.
Also, when you have to debug your bash scripts, execute with '-x' flag. [bash -x s.sh].