Bash - 编写一个函数,打开具有特定名称的最近目录
Bash - Write a function that opens the closest directory with a certain name
我想创建一个带有 1 个参数的 Bash 函数 goto
如果当前目录包含一个由参数名称的目录,cd
到它
如果当前目录的任何一个目录包含它,cd
那里
等...
如果当前目录的所有路径都用完了,echo "File could not be found"
我对Bash的了解非常简陋;我只知道命令、if 语句和函数的基本语法。
因此,我想要对组件的解释(或 link 对其他地方的解释)。
玩转:
goto() { local CDPATH; printf -v CDPATH "%s:" */; cd "" 2>/dev/null || echo "File could not be found"; }
我想创建一个带有 1 个参数的 Bash 函数 goto
如果当前目录包含一个由参数名称的目录,cd
到它
如果当前目录的任何一个目录包含它,cd
那里
等...
如果当前目录的所有路径都用完了,echo "File could not be found"
我对Bash的了解非常简陋;我只知道命令、if 语句和函数的基本语法。
因此,我想要对组件的解释(或 link 对其他地方的解释)。
玩转:
goto() { local CDPATH; printf -v CDPATH "%s:" */; cd "" 2>/dev/null || echo "File could not be found"; }