使用 FOR 循环,当条件为真时结束
这是我的脚本:
dir="/path/to/a/folder"
for d in /Users/*
do
if [ -e $d/Desktop/*file ]
then
$dir/./script.sh
exit
else
/usr/bin/osascript <<-EOF
tell application "System Events"
activate
display dialog "Some text"
end tell
EOF
killall MyProgram
fi
done
目前,该脚本在用户桌面中查找唯一的文件,然后如果该文件存在则执行另一个脚本,否则它会杀死 MyProgram,这对于每个用户都是如此。
我想做的是,只有当该文件不存在于任何用户的桌面中时,脚本才会执行 else
中的命令,否则一旦发现该文件,它就会停止循环脚本并运行该脚本。
感谢您的帮助 !
here is my script :
dir="/path/to/a/folder"
for d in /Users/*
do
if [ -e $d/Desktop/*file ]
then
$dir/./script.sh
exit
else
/usr/bin/osascript <<-EOF
tell application "System Events"
activate
display dialog "Some text"
end tell
EOF
killall MyProgram
fi
done
Currently, the script looks an unique file in an user's desktop, then executes another script if the file exists, otherwise it kills MyProgram, and this for each user.
What I would like to do is that the script executes the commands in the else
only when the file does not exist in ANY users' desktop, otherwise it stops the loop as soon as the file is found by the script and the script is run.
Thanks for your help !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用另一个变量:
编辑:实际上这很愚蠢。如果您要在第一个脚本运行后退出,则根本不需要该变量:
Use another variable:
Edit: actually that's stupid. You don't need the variable at all if you're going to exit after the first script is run: