Jac*_*ob_ 6 bash bash-scripting
我不知道这是一件坏事,还是意味着什么。我的脚本似乎仍然可以正常工作,但我应该修复它吗?
#!/bin/sh
#This script will send text and maybe images to other computers via ssh and scp.
#Configuration files in same folder
source /Users/jacobgarby/Desktop/messaging/messages.cfg
TIME=$(date +"%H:%M:%S")
CONNECTED[0]="mainmini@192.168.1.65"
if [ -d messages.log ]; then
:
else
touch messages.log
fi
read MSG
if [ "$MSG" == "!help" ]; then
echo ; echo "!clear Clear's your personal chat log."
echo "!ban [usrname] Prevents a user from entering this chat IN DEV."
else
echo "$TIME | $USER | $MSG" >> messages.log; echo >> messages.log; echo >> messages.log
tail messages.log
fi
for CONNECTION in CONNECTED; do
echo "It works"
done
if [ "alerttype" == "notification"]; then
osascript -e 'display notification "You have recieved a message!" with title "Message"'
else
osascript -e 'display dialog "You have recieved a message!" with title "Message"'
fi
Run Code Online (Sandbox Code Playgroud)
Dav*_*ill 11
您正在使用以下内容:
if [ "alerttype" == "notification"]; then`
Run Code Online (Sandbox Code Playgroud)
但是,上面的命令缺少一个spacebefore ],应该是:
if [ "alerttype" == "notification" ]; then
^
Run Code Online (Sandbox Code Playgroud)
当您开始编写和使用自己的条件时,您应该了解一些规则,以防止出现难以追踪的错误。以下是三个重要的:
始终在括号和实际检查/比较之间保留空格。以下将不起作用:
if [$foo -ge 3]; thenBash 会抱怨“缺少']'”。
你少了一个空格。
#BEFORE
if [ "alerttype" == "notification"]; then
#AFTER
if [ "alerttype" == "notification" ]; then
# ^
Run Code Online (Sandbox Code Playgroud)
另一个例子:
$ if [ "a" == "a"]; then echo "yes"; else echo "no"; fi
-bash: [: missing `]'
no
$ if [ "a" == "a" ]; then echo "yes"; else echo "no"; fi
yes
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8315 次 |
| 最近记录: |