< stdin
Bash shell uses stdin to take input. In input redirection. A file is made input to the command and this redirection is done with the help of ‘<‘ sign.
Sample syntax command of ca < commmand :
# cat < <filename>
Like example of ca < command :
# cat < file.txt
See your terminal after run the command, command “cat < file.txt” has taken ‘file.txt’ as input and displayed its content.
<< here document
The here document sometimes also called here-is-document, is a way in which you can enter input until a certain sequence(usually EOF) is type. The EOF (End Of File) can be type or can be calle by pressing (ctrl + d) keys.
Any word can be use in place of ‘EOF’ like we have used ‘last’.
Sample syntax of cat < <EOF> :
# cat < <EOF> <filename>
Like example of cat << <EOF> :
# cat <<EOF> file.txt
See your terminal after run the command, in first example, ‘file.txt’ is end when we typed ‘EOF’ and ‘last‘ in second example.
<<< here string
The here string is used to directly pass strings to a command.
Like example of <<< :
# base64 <<< format.txt
See your terminal, in this example we have used base64 which we’ll study later. Command “base64 <<< format.txt” has decoded file ‘format.txt’ and then by using command ‘base64 -d’ we got back our file ‘format.txt’.
Linux Output Redirection
Output redirection is use to put output of one command into a file or into another command.
stdout
The stdout is redirect with a ‘>’ greater than sign. When shell meets the ‘>’ sign, it will clear the file as you already know.
Like example of > :
# echo Hello everyone. > afile.txt
See your terminal after run the command, greater than sign ‘>’ redirects the command ‘echo’ output into a file ‘afile.txt’.
Output File Is Erased
In output redirection, during scanning of a command line, shell will encounter through ‘>’ sign and will clear the file.
Like example of file ereased :
# zcho Welcome > afile.txt
See your terminal after run command, command “zcho Welcome > afile.txt” is wrong but still file ‘afile.txt’ is clear.
noclobber
We can prevent file deletion while using ‘>’ sign with the help of noclobber option.
Sample syntax of noclobber :
# set -o noclobber (To prevent overwrite)
# set +o noclobber (To overwrite)
Like example of noclobber :
# echo Learn Linux. > newfile.txt
See your terminal after run the command, command “set -o noclobber” prevents file from getting overwrite.
set +o noclobber command allows you to overwrite the existing file.