From the course: Linux System Engineer: Bash Shell Scripting for Automation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Outputting to STDOUT and STDERR

Outputting to STDOUT and STDERR

From the course: Linux System Engineer: Bash Shell Scripting for Automation

Start my 1-month free trial

Outputting to STDOUT and STDERR

- [Instructor] To make our script act more like Linux commands, we will send text to standard out and standard error depending on what it is. Sending text to standard out is as simple as using echo or printf. By default, all text goes to standard out. However, if you want to send text to standard error, you will need to use different syntax. Make sure you're in your tilde/bin directory and let's create a new file. Type in vi space scriptoutput.sh and hit Enter. Go into Insert mode and add hash bang slash bin slash bash and hit Enter. Type in echo space double quote This part of the script worked. Double quote. New line. Type in echo space double quote Error: this part failed. Double quote Space >&2 and hit Enter. Now save by pressing ESC:W and hit Enter again. Now let's flip to our second terminal, make it executable and run it. Type in chmod space u+x space scriptoutput.sh and hit Enter. Not let's run it by typing in scriptouput.sh and hit Enter. It's hard to figure out what happened…

Contents