It's UWAweek 50

helpOSTS

This forum is provided to promote discussion amongst students enrolled in Open Source Tools and Scripting.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying the 4 articles in this topic
Showing 4 of 445 articles.
Currently no other people reading this forum.


 UWA week 13 (1st semester, week 5) ↓
SVG not supported

Login to reply

👍?
helpful
9:06pm Tue 26th Mar, Suan C.

Hi Michael, may you please explain the difference between the usage of dev/null and dev/stderr that you covered in lectures? What is the purpose of using these?


SVG not supported

Login to reply

👍?
helpful
4:01pm Wed 27th Mar, Michael W.

"Suan Chuah" <20*0*5*2@s*u*e*t*u*a*e*u*a*> wrote:
> Hi Michael, may you please explain the difference between the usage of dev/null and dev/stderr that you covered in lectures? What is the purpose of using these?
Hi Suan, They are both places where standard output, e.g. from echo, can be redirected. /dev/stderr (don't forget the first '/' ) is standard error output (for error messages), while /dev/null is literally nowhere, a black hole, which simply gobbles up whatever data you send there, and that is used for outputs that you are not interested in seeing, but can't otherwise avoid. Cheers MichaelW


 UWA week 14 (1st semester, non-teaching week) ↓
SVG not supported

Login to reply

👍?
helpful
10:28pm Thu 4th Apr, Suan C.

Hi Michael, thanks for the explanation. Under what circumstances would we use /dev/null and /dev/stderr? For example (let's take assignment as an example here), if i just put "echo" in generating the outputs, why would we still need to use those /dev/..?

I sort of understand the purposes - just not the scenario of when to or when to not use this.


SVG not supported

Login to reply

👍?
helpful
9:39am Fri 5th Apr, Michael W.

Hi Suan, For example, let's say that the argument to this program is a word $1 being sought in a text $2 if [[ grep $1 $2 > /dev/null ]] then echo "The word: $1 is found in $2" else echo "The word: $1 is not found in $2" fi In this case we don't want all the instances, which are dumped to /dev/null so won't be seen by the user

Alternatively, if you are checking an argument to make sure it's greater than or equal to zero, the error message goes to /dev/stderr, which keeps the error handling away from /dev/stdout (the good stuff). Of course, you are able to combine the two streams if you wish

my_long_running_analysis > results 2>&1 &

This fires off the analysis asynchronously (&) and dumps both stdout and stderr into the file results.

Cheers MichaelW

Cheers MichaelW

If

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy