开发者

function accepts a command string but not Aliases

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

+ whoami

root

$ doit wi

+ wi doit[6]: wi: not found

Can 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 "$@".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜