Documente Academic
Documente Profesional
Documente Cultură
in Linux
Though not a part of scripting only, input output redirection in Linux can be used for other
purposes as well. Now before we discuss about input output redirection in Linux in detail. Let’s
discuss about redirecting the output of a script to a file.
Also Read: How to setup SSH login without password on Linux systems
#!/bin/bash
do
if [ -d “$file” ]
then
elif [ -f “$file” ]
then
else
In the last line, we redirected the output to a file named ‘result.txt’. Now let’s discuss about input
output redirection in Linux
STDIN refers to standard Input for the shell, which by default is the keyboard. But we can a file
as standard input using “>” symbol.
STDOUT refers to standard output for the shell, which is monitor by default. But we can redirect
output to a file with “<” symbol.
STDERR refers to standard error output to the shell, which is monitor by default. But are also
redirected to a file when we redirect STOUT to a file.
#!/bin/bash
ls -a /home/example_directory
In this simple script, we used two commands, first command will throw output as there is no
directory by that name & then second command will run successfully. Now let’s see how to
handle the errors & successful outputs to files.
Now the successful output will be printed on screen & the error message will go to a file.
Here, 2 > will redirect errors for the script to “errors.txt” & 1> will redirect output to “output.txt”.
With this our tutorial is complete, send any suggestions, queries or questions using the
comment box below.
If you think we have helped you or just want to support us, please consider these:-
TheLinuxGURUS.com