cat command with a variable that has spaces
9,947
You have to quote the variable too:
I="embedded board link.rtf"
cat "$I"
This is because the shell will first expand any variables, and then parse the command:
cat $1
cat embedded board link.rtf
When you really meant the following:
cat "$1"
cat "embedded board link.rtf"
Note that in bash
and many other shells, variables inside single quotes will not be expanded:
cat '$1'
cat '$1'
Related videos on Youtube
Author by
Obi Wan Kenobi
Updated on September 18, 2022Comments
-
Obi Wan Kenobi over 1 year
I need to use
cat
command to display the contents of a file, and the filename has spaces in them: "embedded board link.rtf".I assign the filename using a variable:
I="embedded board link.rtf"
, but when I usecat $I
, I have this error message.wireless-10-146-35-118 Desktop> cat $I cat: embedded: No such file or directory cat: board: No such file or directory cat: link.rtf: No such file or directory
What might be wrong?