bash:尝试运行打开 xterm 然后更改目录的命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12532474/
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
bash: trying to to run a command that open xterm and then change the directory
提问by ziiweb
I'm trying create a command to open xterm and then change the directory that shows xterm by default.
我正在尝试创建一个命令来打开 xterm,然后更改默认显示 xterm 的目录。
I'm pressing Alt+F2 and then i run xterm | cd /home/tirengarfio/Music, but it doesn't change the directory...
我按 Alt+F2 然后我运行xterm | cd /home/tirengarfio/Music,但它不会改变目录...
I know that i could change the default directory that xterm shows by default, but I'm interested in do it dynamic: this time I want to go Music but the next time I will be interested in another folder..
我知道我可以更改默认情况下 xterm 显示的默认目录,但我有兴趣做动态:这次我想去音乐,但下次我会对另一个文件夹感兴趣..
Any idea?
任何的想法?
回答by unwind
If that is the literal command you're running, I don't understand your reasoning. Pipes are for sending text data between processes, and that's not at all what you're trying to do.
如果这是您正在运行的文字命令,我不明白您的推理。管道用于在进程之间发送文本数据,而这根本不是您想要做的。
You should pass xterm the -eoption to start the desired shell, and then pass the shell a suitable option to set the initial directory.
您应该向 xterm 传递-e启动所需 shell的选项,然后向 shell 传递一个合适的选项来设置初始目录。
Assuming bash, something like xterm -e /usr/bin/bash -c "cd /home/tirengarfio/Music"should be close, you might need to tweak the quoting. The absolute path to the bashbinary might be wrong too, that can be made cleaner but I wanted to keep it simple so I stuck with the absolute.
假设 bash 之类的东西xterm -e /usr/bin/bash -c "cd /home/tirengarfio/Music"应该很接近,您可能需要调整引用。bash二进制文件的绝对路径也可能是错误的,这可以变得更清晰,但我想保持简单,所以我坚持使用绝对路径。
回答by kao
For anyone stumbling on this, this works:
对于任何在这方面绊倒的人,这有效:
uxterm -e "cd /myfolder/anotherfolder && bash"
If I understand correctly, a terminal by itself is just an empty window that programs can display their output in. To be able to interact with it, you'll have to start a program in it, otherwise it will execute the commands it got from -e and immediately disappear. The most common program that gives you your much loved and missed default terminal style interaction is bash.
如果我理解正确的话,终端本身只是一个空窗口,程序可以在其中显示其输出。为了能够与之交互,您必须在其中启动一个程序,否则它将执行它从中获得的命令-e 并立即消失。为您提供深受喜爱和错过的默认终端样式交互的最常见程序是 bash。
回答by ferbuntu
Maybe the thing you want to do is:
也许你想做的事情是:
xterm & cd /home/tirengarfio/Music
I'm not sure why so i cant give you a deep explanation. But i've used it before.
我不知道为什么,所以我不能给你一个深刻的解释。但是我以前用过。

