更改在bash目录与波浪号文件中指定的目录 [英] Change directory in bash to a directory specified in a file with tilde
本文介绍了更改在bash目录与波浪号文件中指定的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件,说:〜/ 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进行扩展。该EVAL导致该命令通过在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.
这篇关于更改在bash目录与波浪号文件中指定的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文