
Here's a preview from my zine, Bite Size Bash!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

read the transcript!
read -r var reads stdin into a variable
$ read -r greeting
hello there!
(type here and press enter)
+ $ echo "$greeting"
hello there!
you can also read into multiple variables
$ read -r name1 name2
ahmed fatima
$ echo "$name2"
fatima
by default, read strips whitespace
" a b c " -> "a b c"
it uses the IFS
(“Input Field Separator”) variable to decide what to strip
set IFS=''
to avoid stripping whitespace empty string
$ IFS=''
(empty string) read -r greeting
hi there!
$ echo "$greeting"
hi there!
the spaces are still there!
more IFS
uses: loop over every line of a file
by default, for loops will loop over every word of a file (not every line). Set IFS=''
to loop over every line instead!
(don’t forget to unset IFS when you’re done!)
IFS=''
for line in $(cat file.txt)
do
echo $line
done
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!