STDIN and ATDOUT Bash

Published: by Creative Commons Licence

Diagram Process

stdin->process->stdout

1.Stdin (Input)

stdin 0 Read input from a file
example :

cat < file

2. Stdout (Output)

stdout 1 Send data to a file (write).
example :

date > output.txt
cat output.txt

3. Stderr(Process)

Stderr 2 Send all error messages in default screen to a file. usually error message when porcess take place.
example :

rm /tmp/test.txt 2> error.txt
cat error.txt

How to direct ouput unwanted?

error message usually there on default screen, if we don’t want error message or message view on screen terminal, we get to throw to device file unix like on /dev/null or /dev/zero

example :

1. remove error message on view

command 2>/dev/null

2. remove message output on view

command >/dev/null

DIrections EOF (End Of File)

Example :

wc -w <<EOF

> This is a test.

> Apple juice.

> 100% fruit juice and no added sugar, colour or preservative.

> EOF

Direction read string

Example :

wc -w <<<“coba test”

grep galuh <<<“galuh tampan sekali”

Direction with other File Descriptor

exec 3< /etc/resolv.conf
cat <&3
output : nameserver 192.168.42.129

remove directions
exec 3<&-
cat <&3
ouput : zsh: 3: bad file descriptor