Schedule
Labs
Assignments
TA office hours
Topic videos
Some course notes
Extra problems
Lecture recordings
a)
echo hello, worldas opposed to
echo 'hello, world'
Answer: The behaviour is the same. In the first case, the echo command sees two command-line arguments, "hello," and "world"; in the second case, the echo command sees just one command-line argument, "hello, world". But in the event of multiple arguments, echo outputs them all separated by spaces, so the output is identical.
b)
x=hello echo '$x, world'as opposed to
x=hello echo "$x, world"
Answer: The first outputs "$x, world" and the second outputs "hello, world", because single quotes suppress the special meaning of the dollar sign whereas double-quotes do not.
c)
cat fileas opposed to
cat <file
Answer: The output is the same, because cat will read its standard input if and only if there are no command-line file names.
d)
sort file | tr x yas opposed to
sort file | tr x y | sort
Answer: The output may be different because the 'tr' may change the sort order.
e)
cat file >file2as opposed to
cat file >file2 2>&1
Answer: If the file exists and is read without error, the behaviour is the same because "2>&1" redirects stderr and there is no stderr output. However, if there is an error of some kind, in the first case the error message is displayed to the stderr of the invoking environment, whereas in the second case the error message goes into "file2".