linux - 如何使用 linux 别名 cd 进入文件夹?

标签 linux bash alias cd

此别名搜索文件夹并打印出该文件夹的位置。

findme 1234567                  --> Searching and printing 
/xxx_data/xxe/TK/1234567/       --> This is the output of above alias.
alias findme='program -x SR $1' --> This is the alias. 

有没有办法重新定义这个别名,当我运行 findme 1231412 时,它会直接将用户输入传递到 cd 并进入子文件夹。

示例

findme 1234567                   
/xxx_data/xxe/TK/1234567 <-- From here I do cd /xxx_data/xxe/TK/1234567/Allfiles

Find me 搜索并打印了文件夹位置,但我希望此别名实际上cd 到找到的文件夹的子文件夹(所有文件)中。 像这样

/xxx_data/xxe/TK/1234567/Allfiles <-- so how can I define an alias that can read user input findme and pass it to cd command 

在此文件结构中,唯一变化的是数字/xxx_data/xxe/TK//Allfiles

最佳答案

别名不带参数。使用函数

findme () {
  cd  "$(program -x SR "$1")"
}

关于linux - 如何使用 linux 别名 cd 进入文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40043802/

相关文章:

git - 我可以在 Git 别名中使用哪些字符?

C# 变量名别名

linux - 无法删除超过三天的目录

python - Shell 命令从 python 失败,从 shell 确定

linux - Shell脚本,将命令值保存到变量

能够模拟非虚拟方法和 C 函数的 C++ 模拟框架

Bash:按内容对 'find' 中的文件进行排序

java - 使用 Java EWS API 检索 "Alias"

linux - Docker如何共享资源

linux - 系统 D-Bus 不允许使用 conf 文件取消所有权