LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-14-2012, 03:02 PM   #1
izual
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Rep: Reputation: Disabled
shell scripting issue


hey guys i'm trying to make a script that will run option 1 or 2 as i saw some tut's on the net i figured
that this should work but i get an error with that ...

Code:
#!/bin/bash
 clear
echo "choose something ..."
select yn in "Yes" "No"; do
       case $yn in 
            Yes ) xterm;;
            No ) echo "hello world";;
            esac
done
the error is :
line 4: syntax error near unexpected token `"Yes"'
line 4: `select yn "Yes" "No"; do'

Last edited by colucix; 01-15-2012 at 10:36 AM. Reason: Children safe editing
 
Old 01-14-2012, 03:10 PM   #2
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,686
Blog Entries: 23

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
Hi,

Let's look at this example:

Quote:
#!/bin/bash
OPTIONS="Hello Quit"
select opt in $OPTIONS; do
if [ "$opt" = "Quit" ]; then
echo done
exit
elif [ "$opt" = "Hello" ]; then
echo Hello World
else
clear
echo bad option
fi
done
$opt is the variable that has the entered value as per list $OPTIONS, whereas in your script:

Quote:
select yn in "Yes" "No"
means two options...

Perhaps a look at the tutorial I consulted may help you...

Good luck

Thor
 
Old 01-14-2012, 03:14 PM   #3
izual
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
thank you very much i will check it out right now
 
Old 01-14-2012, 07:27 PM   #4
Dick Dastardly
LQ Newbie
 
Registered: Jul 2011
Posts: 23

Rep: Reputation: Disabled
I don't get any errors from the output of your code?


Is this any help?

Code:
#!/bin/bash
while true; do
    echo -e " 1)Yes\n 2)No"
    read -p "Choose something: " answer
    case $answer in
        1)
            echo "yes" ;;
        2)
            echo "no" ;;
	*)
	    break  ;;
    esac
done

Last edited by Dick Dastardly; 01-14-2012 at 07:56 PM.
 
Old 01-14-2012, 11:31 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,255

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
I too copied your script and it seems to work without issue.
 
Old 01-15-2012, 09:44 AM   #6
devUnix
Member
 
Registered: Oct 2010
Location: Bengaluru, India
Distribution: RHEL 5.1 on My PC, & SunOS / Sun Solaris, RHEL, SuSe, Debian, FreeBSD and other Linux flavors @ Work
Posts: 576

Rep: Reputation: 48
Quote:
Originally Posted by izual View Post
hey guys i'm trying to make a script that will run option 1 or 2 as i saw some tut's on the net i figured
that this should work but i get an error with that ...

Code:
#!/bin/bash
 clear
echo "choose something ..."
select yn in "Yes" "No"; do
       case $yn in 
            Yes ) xterm;;
            No ) echo "hello world";;
            esac
done
the error is :
line 4: syntax error near unexpected token `"Yes"'
line 4: `select yn "Yes" "No"; do'
Well, I copied and executed your original script and it is working fine:

Code:
choose something ...
1) Yes
2) No
#? 1
./script.sh: line 6: xterm: command not found
#? 2
hello world
#? ^C
[demo@localhost Bash]$ cat script.sh 
#!/bin/bash
 clear
echo "choose something ..."
select yn in "Yes" "No"; do
       case $yn in 
            Yes ) xterm;;
            No ) echo "hello world";;
            esac
done
[demo@localhost Bash]$

Note: Did you copy and paste or type the script?

Try this:

Code:
dos2unix scriptName.sh

Refer to this document for details on dos2unix:

http://linux.about.com/od/commands/l...l1_dos2uni.htm

Last edited by colucix; 01-15-2012 at 10:38 AM. Reason: Children safe editing in quoted post
 
Old 01-15-2012, 09:46 AM   #7
izual
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
i still dont get it why my first script was wrong as i understood from you guys it should work ... :\
Thors helped me out with this but i'm still got question marks above my head.. :\
 
Old 01-15-2012, 10:27 AM   #8
vp0619520
Member
 
Registered: Jan 2012
Posts: 55

Rep: Reputation: Disabled
Hi,I copied your script and it seems to work without problem。What is the editor you are using?
 
Old 01-15-2012, 10:48 AM   #9
izual
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
tried emacs and vim...
got same result
used sh script.sh
or
bash script.sh
 
Old 01-15-2012, 10:53 AM   #10
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
What is the output of
Code:
bash -x script.sh
? Could you copy/paste it from your terminal? Thanks.
 
Old 01-15-2012, 11:38 AM   #11
izual
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
i'm trying 2 copy that using bash -x script.sh > scripterror.txt
but i get some "jeibrish" ( + the echo )
i got the clear command before echo but nothing special same error as before i can take out the 'clear' and make screen shot maybe u will see something i dont ...
 
Old 01-15-2012, 12:01 PM   #12
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
It would be enough if you could copy and paste the whole output here (using CODE tags). The output of
Code:
od -c script.sh
would be useful as well, to see if there are some hidden characters that may trigger the error. Again, copy and paste the untouched terminal output would be the best.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting text file creation issue AiresTheBold Linux - Newbie 1 02-16-2011 10:27 AM
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-27-2008 12:50 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell scripting: "formatting" issue with text files eur0dad Programming 3 08-17-2006 11:50 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM


All times are GMT -5. The time now is 02:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration