sap
sap

Reputation: 679

how to print proper error message

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 message to a text file How i can do this

Upvotes: 1

Views: 1164

Answers (2)

Mikkel Gadegaard
Mikkel Gadegaard

Reputation: 386

In your case

$ ./dir.sh 2 > log.file

should put you error message in the file log.file

Upvotes: 2

sashang
sashang

Reputation: 12234

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.

Upvotes: 1

Related Questions