The report.sh script counts the lines in the files you pass to it. It copes with notes.txt. Now you need the line count of my file.txt. The name has a space, so you put it in quotes, as in the lesson “Help and the shell”.
Pass the script a name with a space
You are in ~/args-lab. Count lines with the report.sh script: first in notes.txt, then in “my file.txt” — the name in quotes.
First, predict
“my file.txt” has three lines, and the name is in quotes. What will ./report.sh "my file.txt" print?
Now start the exercise, run the command and compare your prediction with the output.
Why did the name fall apart into my and file.txt even though you put it in quotes?
-
lsshows one file,my file.txt. There are no files calledmyandfile.txt— that is exactly what wc reported. -
Quotes change nothing in the name; they keep it as one word.
lsshows the filemy file.txtwith its space. -
wc -l "my file.txt"in the terminal prints3 my file.txt: given the whole name, wc opened the file.
The name reached report.sh as one argument and fell apart again inside the script.