首页 > 解决方案 > 如何在 bash 中打开文件夹中的文件?

问题描述

我在 repl.it 上使用 Bash。我正在制作自己的命令行,我想知道如何从名为 commands 的文件夹中运行脚本。基本上,我想让一个文件从一个文件夹运行。我怎样才能做到这一点?

描述我想做什么的图片

链接到我的repl

标签: bashshellrepl.it

解决方案


你能像这样运行它吗?

sh commands/${input}.sh

此外,您应该能够 push/pop dir 进入/退出目录。

pushd commands
# adds cwd into a stack and goes to <dir> commands/
sh $input.sh
popd 
# goes back to last dir in stack.  

推荐阅读