dev*_*evo 9 filesystem command-line bash scripts
我的install.sh当前目录中有一个 bash 脚本,我有一个apps包含多个目录的目录。我想遍历 app 文件夹中的这些子目录并执行一些脚本。在第一个文件夹中执行脚本后,它应该返回并进入下一个文件夹。我试过这个,但它一个接一个地跳过。我的意思是它进入所有奇数文件夹而不进入偶数文件夹。
输入代码 install.sh
for f in apps/*;
do
[ -d $f ] && cd "$f" && echo Entering into $f and installing packages
cd ..
done;
Run Code Online (Sandbox Code Playgroud)
αғs*_*нιη 10
使用您的父目录的完整路径(在我的情况下apps位于我的主目录中的目录)并删除一个额外的命令(cd ..)
for dir in ~/apps/*;
do
[ -d "$dir" ] && cd "$dir" && echo "Entering into $dir and installing packages"
done;
Run Code Online (Sandbox Code Playgroud)
见截图:使用cd ..命令和使用apps/*

见截图:没有cd ..命令和使用~/apps/*

| 归档时间: |
|
| 查看次数: |
64444 次 |
| 最近记录: |