开发者

How to capture the return value (no error code) in unix shell command?

i am trying to capture the return value of simple command:

i.e:

pwd

where can i find the relevant return value without stdout it to file?

Than开发者_开发技巧ks koby


you can use `pwd`

for example:

$ setenv MY_PWD `pwd`
$ echo $MY_PWD
/my/current/path


You can try `pwd`

ole@...:~$ echo `pwd`
/home/ole
ole@...:~$


The first question people should be asking is... what shell are you running this in?

$ MY_PWD=$(pwd) will work in sh-like.

I think the `pwd` will call a subshell, but again, depending on the shell, the syntax to set the output value to a variable will depend on your shell.


echo $?

Is that what you are looking for?


http://tldp.org/LDP/abs/html/exit-status.html

use $?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜