1

This is my code:

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'

The code runs up to the part where it asks for the link. When I provide it with a link I get the following error:

-bash: station=http://www.cidadefm.iol.pt/player/player.html?: No such file or directory

Does anyone have any idea of what might be wrong?

4

2 に答える 2

3

WhatsWrongWithMyScript.comは、"don't" のアポストロフィが単一引用符で囲まれた式を終了していることを指摘しています。「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、引用符の外で使用していることです。おそらく&コマンドの分割があります。

「ステーション」変数名を2つの異なる目的で使用しているようです。それは紛らわしいです。

また、それらすべてをエイリアスに入れるのはちょっと厄介です。関数を使用します

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 に答える