@György-Farkas
Thank you very much. I never thought of that. I'll try it and let it know. I wrote it in the editor.
Posts made by Glenn De Vriendt
-
RE: sh script if then else error
-
RE: sh script if then else error
Thanks @György-Farkas
When I run the script, I see this:
root@Omega-FAF7:~# sh /root/case2.sh : not found.sh: line 2: : not found.sh: line 4: /root/case2.sh: line 5: syntax error: unexpected word (expecting "in") root@Omega-FAF7:~#
-
RE: sh script if then else error
Thanks @György-Farkas
The default shell is indeed 'ash'. I changed the shebang to #!/bin/ash but I've got the same result.
-
RE: sh script if then else error
Thanks for your tips. I changed the € into # and the quotes after echo. The else was for having a default (which I would change later in the first if => $1 = 1 OR $1 IS NULL).
if [ "$1" = "1" ] then echo "##########################################" echo "## launching webradio Hitradio Maroc... ##" echo "##########################################" url=http://hitradio-maroc.ice.infomaniak.ch/hitradio-maroc-128.mp3 elif [ "$1" = "2" ] then echo "####################################" echo "## launching webradio Topradio... ##" echo "####################################" url=http://jwmp3.topradio.be/topradio.mp3 fi
I still have the same error:
####################################
'## stop playing sounds... ##
####################################
: no process killed
parameter
: not found: line 8:
webradio.sh: line 36: syntax error: unexpected end of file (expecting "then")
root@Omega-FAF7:~#Even if I run the most basic script I get the same error:
#!/bin/bash # Basic if statement if [ 1 = 1 ] then echo "Equal" fi
if.sh: line 6: syntax error: unexpected "fi" (expecting "then")
I also tried to change #!/bin/bash to #!/bin/sh or leave it but saddly the same result.
Also a simple case statement doesn't work:
#!/bin/sh # use case statement to make decision case $choose in "one") echo "First option.";; "two") echo "Second option.";; "three") echo "Third option.";; "four") echo "Fourth option.";; "five") echo "Fifth option.";; "six") echo "Last option.";; *) echo "Sorry, no parameter found!";; esac
root@Omega-FAF7:~# sh case.sh "one"
: not foundne 2:
case.sh: line 4: syntax error: unexpected word (expecting "in")Do I need to install something for using this statements?
Thanks in advance.
-
RE: sh script if then else error
Thanks for your reply. I tried both: the then on the second line and with a ; but it is the same:
if [ "$1" = "1" ]
then
echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
echo €€ launching webradio Hitradio Maroc... €€
echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
url=http://hitradio-maroc.ice.infomaniak.ch/hitradio-maroc-128.mp3elif [ "$1" = "2" ] then echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ echo €€ launching webradio Topradio... €€ echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ url=http://jwmp3.topradio.be/topradio.mp3 #else echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ echo €€ launching webradio Hitradio Maroc... €€ echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ url=http://hitradio-maroc.ice.infomaniak.ch/hitradio-maroc-128.mp3 fi
result: line 36: syntax error: unexpected end of file (expecting "then")
and
if [ "$1" = "1" ]; then
echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
echo €€ launching webradio Hitradio Maroc... €€
echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
url=http://hitradio-maroc.ice.infomaniak.ch/hitradio-maroc-128.mp3elif [ "$1" = "2" ] then echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ echo €€ launching webradio Topradio... €€ echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ url=http://jwmp3.topradio.be/topradio.mp3 #else echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ echo €€ launching webradio Hitradio Maroc... €€ echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ url=http://hitradio-maroc.ice.infomaniak.ch/hitradio-maroc-128.mp3 fi
but result also in line 35: syntax error: unexpected end of file (expecting "then")
I really don't know what I do wrong.
Best regards,
Glenn -
sh script if then else error
Hello,
I'm just using my Onion Omega2+ and an asolutely newbie. I made my first very simple script to play a webradio on my boxes and it was a success. Now I want to play several channels by using arguments, first with only 2. When I run my script (sh webradio.sh 2) I've got a syntax error: unexpected "elif" (expecting "then").
script:
_Webradio () {
echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€
echo €€ stop playing sounds... €€
echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€
killall mpg123
echo parameter $1if [ "$1" = "1" ] then echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ echo €€ launching webradio Hitradio Maroc... €€ echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ url=http://hitradio-maroc.ice.infomaniak.ch/hitradio-maroc-128.mp3 elif [ "$1" = "2" ] then echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ echo €€ launching webradio Topradio... €€ echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ url=http://jwmp3.topradio.be/topradio.mp3 #else echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ echo €€ launching webradio Hitradio Maroc... €€ echo €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ url=http://hitradio-maroc.ice.infomaniak.ch/hitradio-maroc-128.mp3 fi echo url=$url mpg123 $url
}
Main Program
run the function and pass in all of the arguments
_Webradio "$1"
output:
€€€€€€€€€€€€€€€€€€€€€€€€€€€€
€€ stop playing sounds... €€
€€€€€€€€€€€€€€€€€€€€€€€€€€€€
: no process killed
parameter 2
: not found: line 8:
webradio.sh: line 15: syntax error: unexpected "elif" (expecting "then")
root@Omega-FAF7:~#Also other very simple script doesn't work with a if then else:
#!/bin/bashBasic if statement
if [ $1 -gt 100 ] then
echo Hey that's a large number.
pwd
fi
dateoutput:
testifelse.sh: line 7: syntax error: unexpected end of file (expecting "th
en")Can someone exlain me what I do wrong? Do I need to install some lib or something? Very simple script do work but a simple if then else does not work.
Thanks in advance.