0

Trying to create a bash script to pick a random radio ip to make mplayer play:

#!/bin/sh
#A simple script to run random radio channels on mplayer

radio = (http://162.253.40.181:8808 http://195.154.69.121:8000 http://108.163.197.114:8103 http://216.245.201.73:9910 http://5.63.145.172:7090)

current = echo $[ 1 + $[ RANDOM % 5 ]]

#echo $current

mplayer $radio{[current]}

I think my array declaration is wrong because the script throws out the following error:

Syntax error: "(" unexpected

2
  • Please take a look: shellcheck.net Commented Dec 24, 2015 at 21:33
  • Thanks @Cyrus - that helped, but I am not able to work on all the suggestions there but I will figure it out eventually. Commented Dec 24, 2015 at 21:46

1 Answer 1

2

var assignments in shell cannot have space chars on either side of =, hence you need

 radio=(http://162.253.40.181:8808 http://195.154.69.121:8000 http://108.163.197.114:8103 http://216.245.201.73:9910 http://5.63.145.172:7090)

Once you fix that, your line

 current = echo $[ 1 + $[ RANDOM % 5 ]] 

has some problems

Try

 current=$(( $RANDOM % 5 ))

or if you really need the 1+, then

 current=$(( 1+ $RANDOM % 5 ))

AND, per your comment/question, you need

mplayer $radio{[$current]}

IHTH

Sign up to request clarification or add additional context in comments.

2 Comments

Will radio[current] point to the right element in the array?
you're correct, that is a problem, see edit at end of my A. Good luck.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.