如何在 Bash 中...使用别名../..?
我知道其他答案允许,alias '...'='cd ../..'但我希望能够使用其他命令将目录寻址到两级,从而允许:
cd ...
ls ...
realpath ...
Run Code Online (Sandbox Code Playgroud)
我已经尝试过alias '...'='../..',但是当尝试使用它时,我得到以下信息:
$ alias '...'='../..'
$ type ...
... is aliased to '../..'
$ cd ...
bash: cd: ...: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我知道别名是用于命令的。在这种情况下,有没有办法为路径实现相同的功能?
这个问题的最佳答案表明,cut可以使用 withtr来根据重复的空格进行剪切
< file tr -s ' ' | cut -d ' ' -f 8
Run Code Online (Sandbox Code Playgroud)
我想要获取目录中多个 Git 存储库的远程地址,并尝试使用以下内容从每个存储库中提取远程 URL 字段:
ls | xargs -I{} git -C {} remote -vv | sed -n 'p;n' | tr -s " " | cut -d ' ' -f1
Run Code Online (Sandbox Code Playgroud)
但是,这会导致(例如)以下输出,其中我可以看到保留了两个连续的空格(Unicode 代码点 32):
origin https://github.com/jik876/hifi-gan.git
origin https://github.com/NVIDIA/NeMo.git
origin https://github.com/NVIDIA/tacotron2.git
Run Code Online (Sandbox Code Playgroud)
(我也使用xargs过tr)
所需的输出是 URL 列表,例如:
https://github.com/jik876/hifi-gan.git
https://github.com/NVIDIA/NeMo.git
https://github.com/NVIDIA/tacotron2.git
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?