猛砸如果既节约了变量配置文件声明不起作用
问题描述:
这是我的代码:猛砸如果既节约了变量配置文件声明不起作用
alias radio='
if [ -e "$station" ]
then
open $station
else
say "I still don't know what your favorite radio station is sir. Would you mind giving me the link?"
echo "What is the link of your favorite station?"
read station
echo "station="$station"" >> ~/.fis/config
say "You can now try the command again."
fi'
的代码运行到哪里,它要求该链接的一部分。当我提供链接时,出现以下错误:
-bash: station= http://www.cidadefm.iol.pt/player/player.html ?: No such file or directory
有没有人有任何想法可能会出错?
答
主要问题是您在引号外使用$station
。可能有一个&
分解命令。
您似乎使用“站”变量名出于两个不同的目的。这很混乱。
另外,有点尴尬把所有的东西放进一个别名。我会使用一个功能
radio() {
local file=~/.fis/config
if [ -f "$file" ]
then
station=$(< "$file")
else
say "I still don't know what your favorite radio station is sir. Would you mind giving me the link?"
echo "What is the URL of your favorite station?"
read staton
echo "$station" > "$file"
fi
open "$station"
}
答
WhatsWrongWithMyScript.com有益指出,“不”被终止单引号表达撇号。不用通过使用“don't”来解决这个问题,请使用函数来代替:
radio() {
if [ -e "$station" ]
then
open $station
else
say "I still don't know what your favorite radio station is sir. Would you mind giving me the link?"
echo "What is the link of your favorite station?"
read station
echo "station=\"$station\"" >> ~/.fis/config
say "You can now try the command again."
fi
}
是'say'一个unix命令吗? – Bill 2013-05-14 00:32:57
@Bill这是一个mac命令。不知道在所有的Unix发行版中是否可用。 – Aslet 2013-05-14 00:36:00
出于好奇...你有一个'./http:/www.ccidadefm.iol.pt/player/player.html'文件在你当前的目录中,从你运行脚本的地方('open $ station') – Bill 2013-05-14 00:41:36