我有一系列目录,它们只是数字标签不同。
arr=(0 1 2 3)
i=0
while [ $i -le ${arr}]
do
dir="~Documents/seed"
dir+=${arr[i]}
echo $dir #works
cd dir #directory not found
#do other things#
done
这有可能吗?
最佳答案
这可能更容易:
#!/bin/bash
for d in ~/Dcouments/seed*
do
if [ -d "$d" ]; then
echo $d
fi
done
注意:
您在 ~/Documents 中也有 tarfile(名称也与通配符匹配),所以我添加了一个 if
语句来检查它是目录还是文件并且只对目录使用react.
关于linux - 使用字符串变量更改 shell 脚本中的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24252680/