Contents / Previous / Next


IO

Values for variables can be read from stdin of form a file: #!/bin/sh # Read from stdin: echo "Hi there" echo "what is your name? (Type your name here and press Enter)" read NM echo "Hello $NM" # Read from data file: echo "Numbers are in one line space separated:" read a b c < data_file echo a = $a echo b = $b echo c = $c echo "Numbers are stored one per line:" { read a read b read c } < data_file echo a = $a echo b = $b echo c = $c Test in shell: ~/tmp> more data_file 1 2 45 33 44 ~/tmp> sh t Hi there what is your name? (Type your name here and press Enter) Felix Hello Felix Numbers are in one line space separated: a = 1 b = 2 c = 45 Numbers are stored one per line: a = 1 2 45 b = 33 c = 44