LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Unix Script Help Need (https://www.linuxquestions.org/questions/programming-9/unix-script-help-need-765857/)

deven1174 10-31-2009 04:08 PM

Unix Script Help Need
 
Hello,
Can anybody help me with a unix script project that I have no clue on starting it, and also I 'm not that much familiar with unix scripting. Don't get me wrong have little bit experience with Linux, but when comes to script I'm just a beginner. If any someone can assist me with project that would be great. At the bottom is the description of the project:

PROJECT 3

Create your own shell that will allow you to change file status and copy from one directory to another.


If someone can help with this project.

Thanks
Deven

michaelk 10-31-2009 04:13 PM

Welcome to LinuxQuestions

Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

dxqcanada 10-31-2009 04:16 PM

What did you learn in Project 1 and 2 ?

Can you apply that to Project 3 ?

Obviously your prof must have explained how to do what you need to do.
Where are you stuck?

ta0kira 10-31-2009 04:22 PM

Creating a shell isn't the same as creating a script, unless you mean to create a script that emulates a shell.
Kevin Barry

deven1174 10-31-2009 05:43 PM

I asked the professor to provided any example that help with doing this project, this what he provided:

Dear Deven:

The menu structure I mentioned can be created with the following template:

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)
# code for hide
copy)
# code for copy
copypro)
# code for copypro
read)
# code for read
exit)
# code for exit
*)
# code for error
esac
else
cd $choice
fi

fi




So if this what's looking for, then I do have the little bit idea. The only part I really stuck is creating a your shell. So, if someone can provided me the material, or guide me on getting the first part clear. Then I can work the project.

Sincerely,
Deven

PS Moderator, I'm sorry about the rule, which I didn't follow. My mistake, and I'll make sure next time.

dxqcanada 11-01-2009 08:51 AM

As ta0kira stated ... are you sure your Prof asked to
Quote:

Originally Posted by deven1174 (Post 3739459)
Create your own shell ...

or did they ask you to:
"Create your own shell script ..."

These are two very different things.

Disillusionist 11-01-2009 11:48 AM

It seems clear from the professors reply:
  1. You are creating a shell script
  2. The script is menu driven
  3. You have covered (or should have) case statements
  4. You have covered reading input and checking the responses

Your professor has also provided the starting point for your homework:
Code:

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)
            # code for hide
        copy)
            # code for copy
        copypro)
            # code for copypro
        read)
            # code for read
        exit)
            # code for exit
        *)
            # code for error
      esac
  else
    cd $choice
  fi
fi

Meaning all you need to do is create the code for each option (hide, copy, copypro etc)

Where are you having difficulties?

ta0kira 11-01-2009 11:56 AM

What does "copypro" mean?
Kevin Barry

Disillusionist 11-01-2009 12:17 PM

As in the professor's instructions copypro (copy protection)

All of the options seem to be permission related, therefore alot of this will probably fall down to using chmod. But there may well be some PAM in use, not being on the course I couldn't say for sure ;)

catkin 11-01-2009 12:31 PM

The prof's code:
  • fails if $choice contains embedded whitespace.
  • does not follow good practice by using [ ] rather than [[ ]] and by using " when ' will do.
  • has a typo of "ready" for "read".
  • is ineffective and lacks error code when the user chooses a "folder" (we have folders on Linux?).

@deven1174: I dare you tell the prof all those things!

deven1174 11-02-2009 07:44 AM

Here's is professor comment:

Yes, file status means permissions enable/disable. I am assuming that you have to provide for all the options you have on lab2. The template I gave you goes beyond that.

Lab2 solution:

#!/bin/ksh

cd North
find ./ -type f -exec chmod 555 {} \;
cd

# in order for a file to be read only and not be useless, it must be executable. Doing chmod 444 as you did is no good.

cd East
find ./ -type f -exec chmod 333 {} \;
cd

cd West
find ./ -type f -exec chmod 333 {} \;
cd

# In order to be copy protected, you must disable the read permission. Doing chmod 744 as you did is no good.

cd South
for var in *; do
if [ -d "$var" ]; then
cd $var
for var in *; do
if [ -d "$var" ]; then
cd $var
for file in *; do
mv "$file" ".$file"
done
cd ..
else
mv "$var" ".$var"
fi
done
cd ..
else
mv "$var" ".$var"
fi
done

# South is more tricky. You do not want to hide the whole South structure, but just the files. So you have to use something like the code above, to find and hide only the files.


I'm kind a beginner when comes to Unix Scripting. I don't mind learning it, but with Project3 is due tomorrow. I kind running out of time. If anybody could help with this Project.

Than You for your help

Deven

ta0kira 11-02-2009 10:46 AM

You haven't actually posted code you've written yourself and tried...
Kevin Barry

pixellany 11-02-2009 11:03 AM

Quote:

I'm kind a beginner when comes to Unix Scripting. I don't mind learning it, but with Project3 is due tomorrow. I kind running out of time. If anybody could help with this Project.
Have you told us what references you are using (I might have missed it..)

Also, what shell? Here in Linux-land, we mostly use BASH, which is derived from the Unix Bourne shell. I'm not sure what all the differences are.

As far as getting help here, the best thing at this point would be to take specific questions---show us your code (or what you have read), and tell us specifically what you don't understand.

Quote:

I don't mind learning it
It seems that it is required for your class, so I'd like to hear: "I want to learn it."

Disillusionist 11-02-2009 03:30 PM

So what you are saying (or quoting) is:

"Read only" equates to chmod 555 "$choice"
"Copy protected" equates to chmod 333 "$choice"
"Hide" equates to mv "$choice" ".$choice"
"Copy" will require asking for the new location (and testing that it is a directory)

It seems to me that you have everything, that your professor has all but spelt out the answer.

dxqcanada 11-02-2009 05:14 PM

Deven ... what we are saying here is ... you show us that you have made an effort in doing your own homework ... and then we will help by offering suggestions to specific points you are having problems with.

We will not do your assignment for you.

Show us what you have done.


All times are GMT -5. The time now is 12:22 PM.