Search code examples
linuxubuntuterminalcd

how to specify path with space inside file in linux


cat ~/.last_dir

/mnt/c/Users/Administrator/OneDrive/Desktop/main project/backup/main project 2

cd cat ~/.last_dir

-bash: cd: too many arguments

I tried using backslash inside the file

/mnt/c/Users/Administrator/OneDrive/Desktop/main\ project/backup/main\ project\ 2

Still same error


Solution

  • You need to quote the results of expanding cat ...:

    cd "$(cat ~/.last_dir)"