开发者

how to print proper error message

开发者 https://www.devze.com 2023-01-31 09:10 出处:网络
I have following small shell script. value=\'testdir/imp\' `mkdir -m 755 $value` echo $ the out put is $ ./dir.sh

I have following small shell script.

value='testdir/imp'
`mkdir -m 755 $value`
echo $

the out put is

$ ./dir.sh 
mkdir: Failed to make directory "testdir/imp"; Permission denied
2

Here i want to print this error mes开发者_如何学Pythonsage to a text file How i can do this


In your case

$ ./dir.sh 2 > log.file

should put you error message in the file log.file


mkdir prints error messages to stderr. You can also redirect the output from stderr to a file. Knowing these 2 things you can do this:

mkdir /etc/test 2>somefile

And then the output from mkdir will be in a somefile.

The syntax 2>somefile redirects stderr to a file called somefile.

0

精彩评论

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