LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 11-04-2009, 07:36 PM   #31
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Cool


Okay I got another error after running this script:

Code:
#!/bin/bash
function f_print_msg {
   echo "Please choose a file or directory. If you choose a directory you will move into that folder. Enter nothing to exit."
   read -p "$(pwd) => " choice


f_print_msg
while [ "$choice" != "" ] ;
do

## Enter your code here
echo "$choice options:"
                      echo "Type hide to hide file."
                      echo "Type copypro to copy protect."
                      echo "Type read to set ready only."
                      echo "Type copy to copy a file from one directory to another."
                      echo "Type exit to choose a different file."
                                            read op

                      case "$op" in

                      hide)
                         mv "$choice" ".$choice";;
                      copy)
                           cp "$choice" "~/$choice";;
                       copypro)
                           chmod 333 "$choice" ;;
                       read)
                          chmod 555 "$choice" ;;
                       exit)
                          exit
                     *) 
                          #code for error
           esac
           else
                     cd $choice
          fi

          fi


 f_print_msg
done
}
Error Message:
Code:
root@localhost Project]# ./Project3
./Project3: line 35: syntax error near unexpected token `else'
./Project3: line 35: `           else'
 
Old 11-04-2009, 07:40 PM   #32
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
check your syntax again. do that before posting. you are not doing enough.
 
Old 11-04-2009, 07:57 PM   #33
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Okay after correcting the syntax, I'm not getting an errors, but I don't if the script that created is what's project is asking for. Can anybody help on that?
Here is Project 3 Description

Quote:
PROJECT 3

Create your own shell that will allow you to change file status and copy from one directory to another.
Code:
#!/bin/bash
function f_print_msg {
   echo "Please choose a file or directory. If you choose a directory you will move into that folder. Enter nothing to exit."
   read -p "$(pwd) => " choice


f_print_msg
while [ "$choice" != "" ] ;
do

## Enter your code here
echo "$choice options:"
                      echo "Type hide to hide file."
                      echo "Type copypro to copy protect."
                      echo "Type read to set ready only."
                      echo "Type copy to copy a file from one directory to another."
                      echo "Type exit to choose a different file."
                                            read op

                      case "$op" in

                      hide)
                         mv "$choice" ".$choice";;
                      copy)
                           cp "$choice" "~/$choice";;
                       copypro)
                           chmod 333 "$choice" ;;
                       read)
                          chmod 555 "$choice" ;;
                       exit)
                          exit ;;
                     *) 
                          #code for error
           esac
           
                     cd $choice
          

          


 f_print_msg
done
}
 
Old 11-04-2009, 08:16 PM   #34
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
You have this line here:
echo "Please choose a file or directory. If you choose a directory you will move into that folder. Enter nothing to exit."

But you don't have anything after to check if the input is a file, or a directory.

Also your syntax is wrong again. Several people including me already corrected this specific syntax error. I'll give you a hint this time.
Check where the f_print_msg function is ending and where it should end.

PS: you can check if a file is a directory with
Code:
if [ -d "$file" ]; then
#... do something
fi

Last edited by ammorais; 11-04-2009 at 08:20 PM.
 
Old 11-04-2009, 08:28 PM   #35
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Cool

okay now I'm getting an error message:


Code
Code:
#!/bin/bash
function f_print_msg {
   echo "Please choose a file or directory. If you choose a directory you will move into that folder. Enter nothing to exit."
   read -p "$(pwd) => " choice


f_print_msg
while [ "$choice" != "" ] ;
do

## Enter your code here
echo "$choice options:"
                      echo "Type hide to hide file."
                      echo "Type copypro to copy protect."
                      echo "Type read to set ready only."
                      echo "Type copy to copy a file from one directory to another."
                      echo "Type exit to choose a different file."
                                            read op

                      case "$op" in

                      hide)
                         mv "$choice" ".$choice";;
                      copy)
                           cp "$choice" "~/$choice";;
                       copypro)
                           chmod 333 "$choice" ;;
                       read)
                          chmod 555 "$choice" ;;
                       exit)
                          exit ;;
                     *) 
                          #code for error
           esac
           
                     cd $choice
         if [ -d "$file" ]; then
#... do something
fi 

          


 f_print_msg
done
Error
Code:
[root@localhost Project]# ./Project3
./Project3: line 39: syntax error near unexpected token `fi'
./Project3: line 39: `fi '
[root@localhost Project]#
 
Old 11-04-2009, 08:41 PM   #36
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
When I suggested...
Code:
   if [ -d "$file" ]; then
#... do something
fi
I didn't mean literally. "$file" is a variable.
It was meant for you to replace with the right one(in this case $choise).
This pretty much shows that you have very much to learn yet. There's nothing wrong with that, but I suggest a different approach for you besides coming to a forum and expecting someone to resolve your school work.
I suggest you a very good tutorial. http://tldp.org/LDP/abs/html/
You will have to learn at learn what variables are for, and how functions work. Any question behind that you are just asking for people to solve it for you, and I doubt anyone here or anywhere will do the school work for you.

I will give you a hint. Study the "tests", "Introduction to Variables and Parameters" and "Loops and Branches" of the link I gave you.
Good luck.
 
Old 11-04-2009, 08:52 PM   #37
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Hey Mann, thank for the reference, but could you able help with Project. I have submit tomorrow. I already started reading Shell Script in 24, then I'll read on your reference.If you can help with this

THanks
Devn
 
Old 11-04-2009, 09:07 PM   #38
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
We're stuck in a loop here: Everyone is giving OP hints, and OP seems to be saying: "just help me".

deven*; A while back, there were a few suggestions about how to debug. (Mine was to insert echo statements to confirm what the program is doing at various steps.) Did you try this or any other similar suggestions?

I can appreciate your frustration but the cycle of "I tried that and now it does this." is not an efficient way to de-bug your code. The only way to do it is to go line-by-line and do tests to see if everything is OK to that point.
 
Old 11-04-2009, 09:42 PM   #39
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
Quote:
Originally Posted by deven1174 View Post
Hey Mann, thank for the reference, but could you able help with Project. I have submit tomorrow. I already started reading Shell Script in 24, then I'll read on your reference.If you can help with this

THanks
Devn
You are not asking: "i really need it so please help me.".
You are asking: "I really need help so please do my homework.".

So it's not a matter of help. You already had plenty of help.
 
Old 11-06-2009, 11:38 AM   #40
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Can anybody help me with this Unix Script? I'm getting the same error message as before.

Thanks
Deven
 
Old 11-06-2009, 11:51 AM   #41
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 deven1174 View Post
Can anybody help me with this Unix Script? I'm getting the same error message as before.
Yes, many people can but few will until you show that you have tried what has already been suggested. Now you've missed the deadline the pressure is off and you can review this thread and the advice given in it, try a few things and report back. It's not that LQers are sadistic bar stewards but we like to give people fishing rods, not fish. If you follow the suggestions given, you will learn about shell script and then you can help yourself.
 
Old 11-06-2009, 01:14 PM   #42
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
Something I have often wondered...

You still have:
Code:
             *) 
                          #code for error
           esac
What would you expect to see in the "code for error" section?

Additionally, your function doesn't seem to finish (at least in the code that you have posted)???
 
  


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
Help with a basic UNIX script mike9287 Linux - Newbie 28 06-02-2006 03:14 AM
script under UNIX\Linux OS symbalino Programming 11 05-28-2006 08:50 AM
unix shell script cxy0481 Programming 9 11-20-2005 09:15 AM
Problem in the Unix Script triplek4ever Linux - Networking 3 10-27-2003 02:25 PM
How to schedule unix script periodically from unix os level??? gopi_20us Programming 2 03-11-2002 07:45 AM


All times are GMT -5. The time now is 08:53 AM.

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