Reputation: 359
I used below 2 commands to change directory. And it seems it failed because the directory name includes space.
$ cat temp.temp
/cygdrive/C/training_course/Our\ Document
$ cd `cat temp.temp`
-bash: cd: /cygdrive/C/training_course/Our\: No such file or directory
However, below one works correctly. So what's wrong with above method? Is there any good way to change directory to one location specified in the contents of some file?
$ cd /cygdrive/C/training_course/Our\ Document
Upvotes: 1
Views: 34
Reputation: 21965
read line <temp.temp && cd "$line"
may work.
This comes in handy when you're dealing with multiple directories in a file. If that is the case do something like :
while read line
do
cd "$line"
//something here
cd ..
done <temp.temp
Upvotes: 2