bash 如何在终端中打开应用程序并传递当前工作目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8635456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open an app in terminal and passing the current working directory?
提问by Alex Coplan
I often want to open the entire directory I'm working in by using the mate
command, but how do I pass in the working directory itself?
我经常想使用mate
命令打开我正在工作的整个目录,但是如何传入工作目录本身?
For example, if I'm working in a rails app and I want to open the app folder into the TextMate tree, I would do mate app
, but how could I pass in the working directory itself (i.e. open the entire rails app in the tree)?
例如,如果我在一个 rails 应用程序中工作并且我想将应用程序文件夹打开到 TextMate 树中,我会这样做mate app
,但是我怎么能传递工作目录本身(即在树中打开整个 rails 应用程序) ?
采纳答案by Mattias Wadman
mate .
will open the currently directory. I use the .
directory a lot, for example open finder for the current directory open .
.
mate .
将打开当前目录。我.
经常使用该目录,例如打开当前目录的查找器open .
。
回答by JohnRos
The command you might be looking for is
您可能正在寻找的命令是
pwd
回答by alk
# Assign the current work directory to the bash script variable 'CWD'.
CWD=$(pwd)
# Print it.
printf "%s\n" ${CWD}
回答by fge
Getting the current directory is as simple as typing pwd
, or echo $PWD
.
获取当前目录就像键入pwd
, 或一样简单echo $PWD
。
Now, if you want to open TextMate in a particular directory, you can do:
现在,如果您想在特定目录中打开 TextMate,您可以执行以下操作:
(cd /target/directory && mate)
回答by Pikaurd
mate `pwd`/yourfile
mate `pwd`/app
Or you can using mate $PWD/app
或者你可以使用 mate $PWD/app
回答by nvvetal
DIR=$(readlink -f echo $PWD
);
IFS='/' read -a array <<< "$DIR";
apath=("${array[@]:0:${#array[@]}-1}");
rpath=$(IFS=/ ; echo "${apath[*]}");
cd $rpath
回答by kenorb
The current working directory as set by the cd command is available in shell variable PWD
, e.g.
由 cd 命令设置的当前工作目录在 shell 变量中可用PWD
,例如