LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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-02-2009, 08:03 PM   #16
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0

Can someone help me with the modifying this Unix Scripting?

echo "Please choose a folder or file. If you choose a folder you will move into that folder. Enter nothing to exit."

read choice

if [ "$choice" != "" ]; then

if [ -f $choice ]; then

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)

copypro)
chmod 333 "$choice"
read)
chmod 555 "$choice"
exit)
exit
*)
# code for error
esac
else
cd $choice
fi

fi
 
Old 11-02-2009, 10:45 PM   #17
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
At first glance, it looks like you ignored a lot of the questions and comments and simply re-posted your script.

Regardless---looking at the code above: What is the question? Have you run it? What does it do?
 
Old 11-03-2009, 03:34 AM   #18
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
Try reading the following:

http://tldp.org/LDP/abs/html/testbranch.html#EX29

This may highlight where you are going wrong with the syntax of your case statement.
 
Old 11-03-2009, 03:05 PM   #19
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Hello,
I know that I have little time to submit this project. The references that I'm referring to is Sam Teach yourself Shell Programming in 24 hours and this link

http://steve-parker.org/sh/escape.shtml.

I guess I have read this material, and hope to do this project myself, but thanks for help on this. If you anybody can provide more help on this, it would great.

Thanks
Deven
 
Old 11-03-2009, 03:15 PM   #20
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
You must seperate arguments to mv with a space character.

Each section of your case statement must be completed by ;;
 
Old 11-03-2009, 03:33 PM   #21
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Hello,
Based upon what the project is asking for Create your own shell that will allow you to change file status and copy from one directory to another. The above script that provide does that provide the solution to Project 3. Or the script is more in depth, and what professor provided.

Thanks
Deven
 
Old 11-03-2009, 04:01 PM   #22
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
There is no way that you could be expected to create your own shell, we can only assume that you are being asked to create a script that asks for file/directory names and process based on this.

Code:
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



f_print_msg()
done
 
Old 11-03-2009, 08:06 PM   #23
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Cool

Can anybody look over this error, I check that line in the script. Can someone tell me what command that goes there?

Thanks

Code:
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

}
Code:
Deven@localhost Project]$ ./Project3
./Project3: line 1: f_print_msg{: command not found
Please choose a file or directory. If you choose a directory you will move into that folder. Enter nothing to exit.
/home/Deven/Desktop/Project => test
./Project3: line 30: syntax error near unexpected token `)'
./Project3: line 30: `                      *)'
[Deven@localhost Project]$

Last edited by deven1174; 11-03-2009 at 08:08 PM.
 
Old 11-04-2009, 01:42 AM   #24
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
Sorry, I posted without testing.

It's been a while since I wrote a function in shell.

Should have been:
Code:
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



f_print_msg
done
 
Old 11-04-2009, 09:45 AM   #25
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Hello,
I'm getting same error message as before, can someone can help with project?

Thanks
Deven
 
Old 11-04-2009, 09:52 AM   #26
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
I'm not following the details here......2 general suggestions:

1. Test your code in small pieces---for example, does it correcty run the function "f_print_message".

2. Put echo statements at key locations so you can see where the script is when it fails.
 
Old 11-04-2009, 09:53 AM   #27
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
put set -x into your script and run again. This will produce diagnostics and you can see where it goes wrong. put in some effort on your part. this is your project after all.
 
Old 11-04-2009, 10:06 AM   #28
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Since I'm at work, and there no Linux machine for me check right now. I have wait until, I get home.
 
Old 11-04-2009, 06:47 PM   #29
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Cool

After I ran this script I got this error message with the modifying the code

Code:
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

}
Code:
root@localhost Project]# ./Project3
./Project3: line 1: f_print_msg{: command not found
Please choose a file or directory. If you choose a directory you will move into that folder. Enter nothing to exit.
/home/Deven/Desktop/Project => test
./Project3: line 41: syntax error near unexpected token `done'
./Project3: line 41: `done'
[root@localhost Project]#
 
Old 11-04-2009, 06:58 PM   #30
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
I've just corrected the syntax. The rest of the program is for you to check.


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
# ... 
# ...
        f_print_msg
done
 
  


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 11:03 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