1

这是我的代码:

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 ?: 没有这样的文件或目录

有谁知道可能出了什么问题?

4

2 回答 2

3

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
}
于 2013-05-14T00:59:42.907 回答
2

主要问题是您$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"
}
于 2013-05-14T00:59:35.470 回答