如何创建将我带到文件夹的 shell 脚本?

Joh*_*xus 0 command-line bash scripts

我有一个特定的工作区,我必须导航到该工作区,该工作区非常长。喜欢/真的/该死的/烦人的/长的/和/它/需要/a/while/to/type。我想编写一个只有cd我自己参与的 shell 脚本,但当然,这行不通。有没有另一种方法可以做到这一点,这样我就可以 cd 进入这个目录而无需输入它?

不要告诉我复制和粘贴。

谢谢!

gle*_*man 5

您不能使用 shell 脚本来更改目录,因为该脚本在不同的进程中运行,并且该子进程无法更改当前 shell 进程的环境。

您需要编写将在当前交互式 shell 中运行的函数或别名。其中之一将起作用:

alias go='cd /really/damn/annoyingly/long/and/it/takes/a/while/to/type'
# or
go() { cd /really/damn/annoyingly/long/and/it/takes/a/while/to/type; }
Run Code Online (Sandbox Code Playgroud)

选择一个,将它保存在你的 ~/.bashrc 中,输入source ~/.bashrc,你应该准备好了。


归档时间:

查看次数:

256 次

最近记录:

7 年,3 月 前