Shell Programming (beginner help)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Programming (beginner help)
# 1  
Old 11-06-2014
Shell Programming (beginner help)

So guys basically I was really sick and couldn't attend the labs and lectures and I went to my lecture hoping he would say ok I will help you from the start but he just said google it. So If it's possible to make the assignment and explain more in detail why is that would be really helpfull.
I can see that it shouldn't be something complicated so .. any help would be great. Thank you.

Assignment
Write an interactive script that allows a user to change the permissions on an existing
file. The script should ask the user for:
● the full pathname of the file,
● and the octal code specifying the permissions required.
The script should report errors (and abort the program) where:
1. no file pathname is given;
2. the file pathname given does not specify an existing file;
3. no octal code is given;
4. the command to change the permissions fails.
You will need to research the following:
1. echo command for displaying messages;
2. read command for taking user input;
3. if command for checking various conditions (blank input, existence of files,
success/failure of an attempted command, etc.)
4. chmod command for changing permissions;
5. ls -l command for displaying directory entries.
You do not need to do a separate check on the validity of permission codes supplied - let
chmod try to execute and deal with success/failure afterwards.Examples
Here's how some example runs would look. In these examples:
● assume the script is called 'ass1';
● user input is shown in bold;
● the file pathnames in the examples are indicative - they may not exist in your
directories.
A successful run would look something like this:
ass1
Please enter the file pathname: dir/myfile
Please enter the octal permissions code: 744
ass1: File dir/myfile has permissions changed to 744 as shown below:
-rwxr-r-- rothwell staff 4096 Sep 11 2014 dir/myfile
An unsuccessful run would look something like this (error type 2: the file
dir/NOTmyfile does not exist):
ass1
Please enter the file pathname: dir/NOTmyfile
Please enter the octal permissions code: 744
ass1: ERROR: File dir/NOTmyfile does not exist.
ass1: USAGE: Enter the pathname of an existing file.
Another unsuccessful run would look something like this (Error type 4: the
permission code is incorrect):
ass1
Please enter the file pathname: dir/myfile
Please enter the octal permissions code: 784
ass1: ERROR: Failed to change permissions on dir/myfile.
ass1: USAGE: Check that the permission code is valid.
Another unsuccessful run would look something like this (Error type 2: no file
pathname given):
ass1
Please enter the file pathname:
ass1: ERROR: No file pathname given.
ass1: USAGE: Please supply the pathname of an existing file.Notes:
Errors should be echoed to the standard error channel and adhere to the standard syntax
shown in the notes. For example:
echo "${0}: ERROR: No file pathname given." 1>&2
echo "${0}: USAGE: Please supply the pathname of an existing file." 1>&2
exit 1
Which, in an example run, would display on the error channel as:
ass1: ERROR: No file pathname given.
ass1: USAGE: Please supply the pathname of an existing file.
All your exits for errors should be given a unique exit status number in the range 1-255.
Pseudocode for assignment 1:
1. Get pathname of file.
2. If pathname of file is blank exit with error message.
3. If pathname of file given does not name an existing file exit with error message.
4. Get permissions code.
5. If permissions code is blank exit with error message.
6. Attempt to change permissions of file name.
7. If failure to change permissions exit with error message.
8. Otherwise confirm successful change and show file's entry in its directory so that
permissions can be seen by user.
# 2  
Old 11-06-2014
Thead closed...
But Welcome to the forums, we have a special forum for home/course work:
https://www.unix.com/homework-and-coursework-questions/
Pease repost , following the special rules that apply:
Rules for Homework & Coursework Questions Forum

All the best
This User Gave Thanks to vbe For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

C shell - a question of a beginner

Hi, can someone explain how this aliases work: alias m 'if ( \!:$ =~ *gz) set status = 1 && most \!:$ || gzcat \!:1 | most ' I mean, I know what it does, but I don't know how - what is \!:$ and \!:1 - how do it used the && and || - what it does with status variable? thanks (3 Replies)
Discussion started by: tzvikao
3 Replies

2. Shell Programming and Scripting

A beginner needing some help programming documents

Hi all, I'm a fairly new beginner with shell programming and python programming. I have a mac (mountain lion OS 10.8.2) and use the terminal for programming. I'm trying to use the unix to easily organize some language data that I am working with. Basically I have to word lists, that I need to... (2 Replies)
Discussion started by: nomadblue
2 Replies

3. Homework & Coursework Questions

Shell Script (beginner)

1. The problem statement, all variables and given/known data: Arguments: http://farm9.staticflickr.com/8070/8212131370_8b6e8c10c5_c.jpg I am given these three arguments. $1, $2, $3 The first argument is the path to a directory. So, how would I go into the directory and compare files? I... (5 Replies)
Discussion started by: spider-man
5 Replies

4. Programming

Shell programming ksh AIX - beginner

Hi! I have two shell scripts - Script1, Script2 Script1, Script2 - have return parameter Script1 - is calling Script2 in Script2 I am calling program sqlldr - if this program is called then I did not get the return parameter from Script1 Do You have any idea how can I avoid this problem. Mroki (6 Replies)
Discussion started by: mroki
6 Replies

5. Homework & Coursework Questions

Shell-script loops beginner

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: "Create a shell script that changes the selected word to another word in all files from selected archive. The... (1 Reply)
Discussion started by: oibanuelos
1 Replies

6. Shell Programming and Scripting

Shell script (beginner) need help...

Hello, I'm new to Sheel script and I need your help for a script I need to develop (for me). Indead, I have a software which log all entry from internet and save it in text file. But, the log is practically unreadable because every 256 characters jump to a new line (even if the message is... (5 Replies)
Discussion started by: acidoangel
5 Replies

7. Programming

beginner to c programming

hii friends i m fairy new to c programming.can any one suggest some good websites and some good books for beginner (6 Replies)
Discussion started by: pankajchandel
6 Replies

8. Shell Programming and Scripting

Beginner Shell Programming Question

Hello all, I am currently try to learn the linux operating system as well as some bash programming. I have come across some online course work which has been very helpful, I have been working through some assignments and since I have no teacher to ask I have come to you experts. So the... (6 Replies)
Discussion started by: g2axiom
6 Replies

9. Shell Programming and Scripting

Beginner shell script help

. ./testFile.sh url=http://ichart.finance.yahoo.com/table.csv?s= suf=&d=5&e=9&f=2009&g=d&a=1&b=4&c=1999&ignore=.csv wget $url$s1$suf; sleep 10; cat header.txt > $s1.txt; chmod 777 $s1.txt; sed '1d' table.csv?s\=$s1 >> $s1.txt; rm -Rf table* Very new at shell scripting as you can see... (3 Replies)
Discussion started by: harte
3 Replies

10. Shell Programming and Scripting

Shell Script for Beginner

I have a folder with lots of file. e.g. a.txt, b.txt, c.txt.... I want to put these files from the source directory and place them in a destination directory in a specific order, such as /destination/a/a.txt, /destination/b/b.txt, /destination/c/c.txt, ...... Please help. Thx :confused: (3 Replies)
Discussion started by: aaron_fong
3 Replies
Login or Register to Ask a Question