Input and Output

Script output is provided by the echo and printf commands, which we described in Screen Output:

echo "Hello world"
Hello world
➜ printf "I am %d years old\n" `expr 20 + 20`
I am 40 years old

Input is provided by the read command, which reads one line from standard input and stores it in a variable:

read name
Sandy Smith <ENTER>
➜ echo "I read the name $name"
I read the name Sandy Smith

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.