在mac中的命令bash文件中使用变量
我创建了一个bash脚本,用于在mac OS中显示5秒的通知在mac中的命令bash文件中使用变量,bash,macos,sh,zsh,oh-my-zsh,Bash,Macos,Sh,Zsh,Oh My Zsh,我创建了一个bash脚本,用于在mac OS中显示5秒的通知 #!/bin/bash arr[0]="0" arr[1]="1" arr[2]="2" arr[3]="3" arr[4]="4" arr[5]="5" arr[6]="6" while true; do rand=$[$RANDOM % ${#arr[@]}] text
#!/bin/bash
arr[0]="0"
arr[1]="1"
arr[2]="2"
arr[3]="3"
arr[4]="4"
arr[5]="5"
arr[6]="6"
while true; do
rand=$[$RANDOM % ${#arr[@]}]
text=${arr[$rand]}
osascript -e 'display notification '"$text"' with title "hello"'
sleep 5
done
但显示标题为hello和description$text的通知。
如何在此命令中使用$text变量?将“$text”
的值作为参数传递给静态脚本
osascript -e 'on run argv' \
-e 'display notification (item 1 of argv) with title "hello"' \
-e 'end run' "$text"
或
另一方面,
$[…]
是一种非常古老和非常过时的算术扩展形式。改用$(…)
。用set-x;osascript;设置+x
?祝你好运。@RasoulMiri:如果没有涉及zsh,为什么它会被标记为zsh?
osascript -e 'on run argv
display notification (item 1 of argv) with title "hello"
end run' "$text"