I have a directory named "test 1" and I create a variable
dest="test\ 1"
I want to navigate to the directory using the cd command, so I type
cd $dest
which gives the output as
-bash: cd: too many arguments
while typing
cd test\ 1
actually works and changes the current directory to "test 1".
Now, I've read a few other questions and know that I've to type in
cd "$dest"
for it to work but I don't understand the reason why. Because $dest will basically substitute the value of the variable dest which is nothing but test\ 1. So why does this not work?
set -x
: Whatbash
actually performs iscd 'test\' 1
. – pLumo Jan 05 '22 at 13:07*?[
.dest='test\ [1]'; cd $test
would work. But of coursecd "$dest"
would not work. Andname='monthly report.txt'; file=$dest/$name; open "$file"
would not work, and wouldn't work withopen $file
either since$file
would contain a mix of a file name and a wildcard pattern. – Gilles 'SO- stop being evil' Jan 05 '22 at 13:08echo "Hello \\"
the output isHello \\
. This means that the second backslash I added was used as an escape character. But if I runecho "Hello\ K"
, the output isHello\ K
. Why isn't the backslash omitted in the output this time? – klaus_03 Jan 05 '22 at 13:26