使用代字号将目录更改为文件中指定的路径 [英] Change directory to a path specified in a file with tilde
本文介绍了使用代字号将目录更改为文件中指定的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件,说:~/cwd
.该文件的内容为一行:
I have a file, say: ~/cwd
. The content of this file is a single line:
~/tmp
我要fo cd
到这个(〜/tmp)目录.我正在尝试:
I want fo cd
to this (~/tmp) dir. I'm trying:
> cd `cat ~/cwd`
得到了:
-bash: cd: ~/tmp: No such file or directory
为什么相对路径失败?当~/cwd
的内容是绝对路径时-它起作用.
Why the RELATIVE paths failed? When the content of the ~/cwd
is absolute path - it works.
推荐答案
尝试一下:
eval cd `cat ~/cwd`
'〜'需要由shell扩展.评估会导致命令在外壳程序的命令处理过程中运行,其中包括〜"扩展.
The '~' needs to be expanded by the shell. The eval causes the command to be run through the shell's command processing, which includes '~' expansion.
这篇关于使用代字号将目录更改为文件中指定的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文