LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-05-2009, 11:00 AM   #1
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Rep: Reputation: 0
Smile Shell Script that has an error to figure out


Hello,
Can anyone can help me with this error message that I'm getting? Here's the error message with the shell script:

Shell Script:
Code:
#!/bin/sh

project=0

while test "$project!=2"
do
echo “SELECT OPTION:”
echo “1) Do you want to change file status and copy to one location to another?”
echo “2) Do you want to search for a file in a particular directories?”
read project
case “$project“ 
       ‘1’)
         echo "Please enter the name of a file:"
         read FILE_NAME
         echo "The file name is:${FILE_NAME}"
         touch "${FILE_NAME}"

         echo "Copypro to copy protect:"
         ls -lt
         chmod 333 "${FILE_NAME}" 
         echo "${FILE_NAME}"
         ls -lt 


        echo "Hide to hide file:"
        chmod 755 "${FILE_NAME}"
        echo "${FILE_NAME}"
        cp "${FILE_NAME}"  ".${FILE_NAME}"
        ls -la

        echo "Read a file to read only:"
        chmod 644 "${FILE_NAME}"
        echo "${FILE_NAME}"
        ls -lt "${FILE_NAME}"


        echo "Copy file from one directory to another place:"
        mkdir Test
        chmod 755 "${FILE_NAME}"
        cp "${FILE_NAME}"  "Test"

        ls -lt
        ls -lt Test

      ;;

 ‘2’)

    echo "Please enter a name or character to find a file."
    read INPUT
    find $HOME -name "${INPUT}"
    find $HOME -name "${INPUT}" -perm 755 "${INPUT}"
    find $HOME -name ".${INPUT}"
    find /home -name "${INPUT}"
    find /home -name ".${INPUT}"
    find / -name "${INPUT}"
    find / -name ".${INPUT}"

     echo "Please enter days of the  file that you are 
     looking for."
     read TIMEFILE
     find $HOME -mtime "${TIMEFILE}" -name "${INPUT}"
     find $HOME -mtime "${TIMEFILE}" -name ".${INPUT}"
     find /home -mtime "${TIMEFILE}" -name "${INPUT}"
     find /home -mtime "${TIMEFILE}" -name ".${INPUT}"
     find / -mtime "${TIMEFILE}" -name "${INPUT}"
     find / -mtime "${TIMEFILE}" -name ".${INPUT}"


    echo "Please enter a name or character to find a file."
    read INPUT1
    echo "Please enter the extension of the file that you are 
    looking for."
    read TEST

    find $HOME -name "${INPUT1}"."${TEST}"
    find $HOME -name ".${INPUT1}."${TEST}"
    find /home -name "${INPUT1}"."${TEST}"
    find /home -name ".${INPUT1}"."${TEST}"
    find / -name "${INPUT1}."${TEST}"
    find / -name ".${INPUT1}"."${TEST}"

  ;;

   exit

   ;;

 esac

done
Error Message
Code:
[root@localhost Desktop]# ./Project5.sh
./Project5.sh: line 8: syntax error near unexpected token `)'
./Project5.sh: line 8: `echo “1) Do you want to change file status and copy to one location to another?”'
 
Old 12-05-2009, 11:09 AM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Code:
test  "$project" != '2'

The way you had it, as a jumbled string within quotations, I believe the test would have always been true. Try the above;

As for the `case` area, you're missing an in operator on the `case` line, and, I'm not sure if your case function will work correctly with those single-quotes around the '1' and '2' (it might, but not sure) -- if not, try removing the quotes.


Sasha
 
Old 12-05-2009, 11:17 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Another problem is slanting double quotes in several places early in the such as around case “$project“.

The single quotes around case statement strings are OK.
 
Old 12-05-2009, 12:04 PM   #4
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
I did modify the script based upon respond. Now I'm getting another error:


Error Message:
Code:
/Project5.sh: line 8: syntax error near unexpected token `)'

./Project5.sh: line 8: `echo “1) Do you want to change file status and copy to one location to another?”'
Shell Script:
Code:
#!/bin/sh

project=0

while test "$project"!='2'
do
echo “SELECT OPTION:”
echo “1) Do you want to change file status and copy to one location to another?”
echo “2) Do you want to search for a file in a particular directories?”
read project
case '$project' 
       1)
         echo "Please enter the name of a file:"
         read FILE_NAME
         echo "The file name is:${FILE_NAME}"
         touch "${FILE_NAME}"

         echo "Copypro to copy protect:"
         ls -lt
         chmod 333 "${FILE_NAME}" 
         echo "${FILE_NAME}"
         ls -lt 


        echo "Hide to hide file:"
        chmod 755 "${FILE_NAME}"
        echo "${FILE_NAME}"
        cp "${FILE_NAME}"  ".${FILE_NAME}"
        ls -la

        echo "Read a file to read only:"
        chmod 644 "${FILE_NAME}"
        echo "${FILE_NAME}"
        ls -lt "${FILE_NAME}"


        echo "Copy file from one directory to another place:"
        mkdir Test
        chmod 755 "${FILE_NAME}"
        cp "${FILE_NAME}"  "Test"

        ls -lt
        ls -lt Test

      ;;

  2)

    echo "Please enter a name or character to find a file."
    read INPUT
    find $HOME -name "${INPUT}"
    find $HOME -name "${INPUT}" -perm 755 "${INPUT}"
    find $HOME -name ".${INPUT}"
    find /home -name "${INPUT}"
    find /home -name ".${INPUT}"
    find / -name "${INPUT}"
    find / -name ".${INPUT}"

     echo "Please enter days of the  file that you are 
     looking for."
     read TIMEFILE
     find $HOME -mtime "${TIMEFILE}" -name "${INPUT}"
     find $HOME -mtime "${TIMEFILE}" -name ".${INPUT}"
     find /home -mtime "${TIMEFILE}" -name "${INPUT}"
     find /home -mtime "${TIMEFILE}" -name ".${INPUT}"
     find / -mtime "${TIMEFILE}" -name "${INPUT}"
     find / -mtime "${TIMEFILE}" -name ".${INPUT}"


    echo "Please enter a name or character to find a file."
    read INPUT1
    echo "Please enter the extension of the file that you are 
    looking for."
    read TEST

    find $HOME -name "${INPUT1}"."${TEST}"
    find $HOME -name ".${INPUT1}."${TEST}"
    find /home -name "${INPUT1}"."${TEST}"
    find /home -name ".${INPUT1}"."${TEST}"
    find / -name "${INPUT1}."${TEST}"
    find / -name ".${INPUT1}"."${TEST}"

  ;;

   exit

   ;;

 esac

done
 
Old 12-05-2009, 12:08 PM   #5
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
Use single quotes for anything that does not contain a $.
 
Old 12-05-2009, 12:15 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
You need an "in" after case '$project' as Sasha wrote
Code:
case '$project' in
 
Old 12-05-2009, 12:17 PM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Quote:
Originally Posted by H_TeXMeX_H View Post
Use single quotes for anything that does not contain a $.
Good advice -- and the corollary is true; you need double quotes, not single quotes, when there is a $ -- so change case '$project' to
Code:
case "$project" in

Last edited by catkin; 12-05-2009 at 12:19 PM. Reason: tyrannous typo trashing
 
Old 12-05-2009, 02:40 PM   #8
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Now I can't figure this error with Line 83, something with the exit command that is implemented.


Error Message
Code:
[root@localhost Desktop]# ./Project5.sh
./Project5.sh: line 83: syntax error near unexpected token `newline'
./Project5.sh: line 83: `   exit'

Shell Script:

Code:
#!/bin/sh

project=0

while test "$project"!='2'
do
echo "SELECT OPTION:"
echo "1) Do you want to change file status and copy to one location to another?"
echo "2) Do you want to search for a file in a particular directories?"
read project
case "$project" in
       1)
         echo "Please enter the name of a file:"
         read FILE_NAME
         echo "The file name is:${FILE_NAME}"
         touch "${FILE_NAME}"

         echo "Copypro to copy protect:"
         ls -lt
         chmod 333 "${FILE_NAME}" 
         echo "${FILE_NAME}"
         ls -lt 


        echo "Hide to hide file:"
        chmod 755 "${FILE_NAME}"
        echo "${FILE_NAME}"
        cp "${FILE_NAME}"  ".${FILE_NAME}"
        ls -la

        echo "Read a file to read only:"
        chmod 644 "${FILE_NAME}"
        echo "${FILE_NAME}"
        ls -lt "${FILE_NAME}"


        echo "Copy file from one directory to another place:"
        mkdir Test
        chmod 755 "${FILE_NAME}"
        cp "${FILE_NAME}"  "Test"

        ls -lt
        ls -lt Test

      ;;

  2)

    echo "Please enter a name or character to find a file."
    read INPUT
    find $HOME -name "${INPUT}"
    find $HOME -name "${INPUT}" -perm 755 "${INPUT}"
    find $HOME -name ".${INPUT}"
    find /home -name "${INPUT}"
    find /home -name ".${INPUT}"
    find / -name "${INPUT}"
    find / -name ".${INPUT}"

     echo "Please enter days of the  file that you are looking for."
     read TIMEFILE
     find $HOME -mtime "${TIMEFILE}" -name "${INPUT}"
     find $HOME -mtime "${TIMEFILE}" -name ".${INPUT}"
     find /home -mtime "${TIMEFILE}" -name "${INPUT}"
     find /home -mtime "${TIMEFILE}" -name ".${INPUT}"
     find / -mtime "${TIMEFILE}" -name "${INPUT}"
     find / -mtime "${TIMEFILE}" -name ".${INPUT}"


    echo "Please enter a name or character to find a file."
    read INPUT1
    echo "Please enter the extension of the file that you are looking for."
    read TEST

    find $HOME -name "${INPUT1}"."${TEST}"
    find $HOME -name ".${INPUT1}."${TEST}"
    find /home -name "${INPUT1}"."${TEST}"
    find /home -name ".${INPUT1}"."${TEST}"
    find / -name "${INPUT1}."${TEST}"
    find / -name ".${INPUT1}"."${TEST}"

  ;;

   exit

  ;;

 esac

done
 
Old 12-05-2009, 03:25 PM   #9
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
That exit should not be there. After the final ;; signifying the end of "case 2)", the next thing the shell expects is esac to close up the case.

After that, you would have your done to close the loop, and you can have an exit then if you like.
 
  


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
awk shell script error ApacheRoseXbones Linux - Newbie 5 07-18-2008 01:06 PM
tar error in shell script fanoliv Programming 4 11-04-2006 04:52 AM
Help With A Shell Script Error PhantomFX Linux - Newbie 3 02-17-2005 05:42 AM
Shell Script Error Gerardoj Linux - General 2 12-03-2003 10:44 AM
Shell script error. chuck77 Linux - General 3 11-30-2001 12:30 AM


All times are GMT -5. The time now is 01:33 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration