1
我在通过我的脚本在我的下标中进行迭代时遇到了一些麻烦。问题似乎是我运行它,它只遍历我的$ @列表的第一个索引。我想它会停下来等待更改,然后继续下一个文件。我的下标的重点是使用我的“单个文件脚本”同时浏览多个文件。如果我更改我的文件,它会继续到下一个索引,但是如果我放弃它,则不会。我希望我让自己清楚。 谢谢!使用subshell通过文件参数进行bash循环
脚本1:
#!/bin/bash
timestamp() {
date +"%T"
}
FILE=$1
timeer=$(stat -f "%Sm" $FILE)
myDate=$(date +%b" "%d" "%H:%M:%S" "%Y)
if [ -f $FILE ]; then
timestamp
echo "Filen{$FILE} ble opprettet"
fi
while :
do
Atimeer=$(stat -f "%Sm" $FILE)
if [[ "$Atimeer" != "$timeer" && -f $FILE ]]; then
timestamp
echo "Filen ble endret!!!"
exit 130
fi
if [ ! -f "$FILE" ]; then
echo "Filen {$FILE} ble slettet.."
exit 130
fi
done
脚本2:
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Not enough arguments, Call this script with"
echo "Write: ${0} <file.name>"
exit 1
fi
while :
do
for i in "${@}"
do
echo $i
sh filkontroll.sh "$i"
done
sleep 3
done
顺便说一句,它运行在后台永远?导致我的Mac现在运行非常激烈。我在终端中运行“top”,即使在我退出脚本之后,我看到了四个sh进程? – ruubel
@ruubel它会在后台运行直到它退出,无论是自然还是被杀死。在您的脚本中,您可以在开始所有脚本后获得很多脚本,等待3秒钟,然后再次启动它们并持续执行。如果脚本中的任何脚本花费超过3秒钟时间,则会越来越多直到系统无法跟上更多 –
噢,我明白了!不,我将其改为60秒。我可以在脚本中使用kill开关吗?或者我应该如何在Im完成时将其取消? – ruubel