I created this doit function to execute system commands, scripts and aliases.
function doit {
doit_cmd=$*
if [[ $cmd_trace = "1" ]] then
echo "+ $doit_cmd"
fi
$开发者_如何学JAVAdoit_cmd
ret=$?
return $ret
}
The doit function accepts a command string (including command parameters). It first displays the given command and its parameters to stdout, then executes the command. I execute commands in scripts via the doit function to trace what commands are executed. The line "$doit_cmd" in the above doit function works beautifully for system commands and scripts, but failed when an alias is given to the doit function.
Here is a demonstration of the problem.
$ alias wi='whoami'
$ cmd_trace=1$ doit whoami
+ whoamiroot
$ doit wi
+ wi doit[6]: wi: not foundCan someone assist me on this problem? Is this a limitation?
Execute your command using: eval $doit_cmd
.
On a separate note, I think you should also change $*
to "$@"
.
精彩评论