Sponsored Content
Homework and Emergencies Homework & Coursework Questions 1st yr Exam revision thread - Scripts, C, Commands Post 302812439 by bakunin on Sunday 26th of May 2013 05:04:40 AM
Old 05-26-2013
Quote:
Originally Posted by murphy
Thanks for the reply I appreciate it, I also wasn't sure if this should be in the homework section, I didn't want to clog it up as I want to keep this alive for a week. If the mods wants to move it they can, and some of the questions I am going to ask are pretty basic Smilie
Moderator's Comments:
Mod Comment Some administrative notes:

I understand that this is a borderline case and appreciate the consideration. Nevertheless you should have contacted any moderator or admin to get a decision on this. In fact we are here to help you and we appreciate being asked for help because this justifies us bossing around innocent users like i do right now. ;-))

My heartfelt thanks go to Don Cragun for showing so much consideration. I really appreciate this.

In my opinion this thread is better suited to the "Homework and Coursework" board and i am going to transfer it there. Please supplement the missing information from the questionnaire, which is obligatory in this part of the board:

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course)


Now to the threads content itself:

Quote:
Originally Posted by murphy
My program is working fine, with any values I throw at it.
Code:
min 205 204

Will output:
Code:
The min of 205 and 204 is 204

The same when the numbers are reversed, I'm happy with that, also I will remember to indent more,ty.
I am not sure if this is in the scope of the question, but i miss some input validation: what will happen in the following cases:

Code:
min 0 -1
min -2 -5
min foo bar
min 1.5 1.6
min 0 1 2
min 1
min

Right now the behavior of your program is not only "unspecified" but also "not determined" and this is generally a bad idea, as the venerable Don Cragun probably knows best of us all.

It is good style to make programs as foolproof as possible, which means: always validate your assumptions. If you get input from users check if it is what you expect it to be. If you allocate temporary space (i.e. by using a tempfile) make sure the file system provides the free space you expect to need. If you want to write a file make sure the privileges the script is run under include write access there - etc., etc., ... True, this makes scripts a lot more complicated (i often end up writing 100 lines for basically executing a single command), but it also will make sure it exits with some defined state.

Always strife to build programs as finite-state machines. They do not always have to carry out their goal, but at least they should respond in a defined way to obstacles. Specifically for your script: it doesn't need to "correct" unintended inputs, but it should react with some defined exit state and/or some error message telling the reason why it can't continue.

Heres some more questions, are the ansers I've given correct? Will they get all the marks?

Quote:
Originally Posted by murphy
b) What is the search path for the shell?
The search path is contained in the C shell “path” variable. Like all C shell variables, it can be referenced by placing a dollar sign in front of the name. The current search path can be printed with % echo $path.
The search path is also a component of the environment which is passed from process to process, independent of the shell.
hmm.... First, I'd like to doubt that you are using or are being tought csh. Using csh is more than antiquated today, it is not POSIXly correct and generally csh Programming Considered Harmful as Tom Christiansen has pointed out already in 1996.

Second, if you indeed use csh: check your answer again, very carefully. UNIX is neither "Unix" nor "unix", you know. ;-))

I hope this helps.

bakunin
 

9 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

deletion of thread backup scripts!!!

I have posted a thread backup scripts. Can you assist in deletion of the said thread. Thanks and Regds Kamlesh (1 Reply)
Discussion started by: kamlesh_p
1 Replies

2. Shell Programming and Scripting

Running shell scripts automatically without using Batch or at commands

I have been trying to run a unix script which contains many sql statements.I need to run this script every monday morning. I tried to run on command prompt, it works fine. But while I run it via batch or at command., it returns with library module could not be loaded (libcompat.1.o could not be... (3 Replies)
Discussion started by: ritzwan0
3 Replies

3. Shell Programming and Scripting

writing shell scripts of commands

can anyone help me in writing a shell script to visualize how simple commands work and on what logic. For Eg: ls command how it lists out all the files and directories, need to write a simple script based on the commands source code.:D (0 Replies)
Discussion started by: rahul_11d
0 Replies

4. UNIX for Dummies Questions & Answers

1st time with scripts

Hello everyone. I am new to writing scripts and I am trying to figure out how to get it to work on a unix system. I am currently using windows xp to write my scripts. My questions are: 1. If the scripts are writtin in Wordpad, what do I save them as before converting them on unix? 2. After... (3 Replies)
Discussion started by: Jeonsah
3 Replies

5. Shell Programming and Scripting

Bash scripts as commands

Hello, the bulk of my work is run by scripts. An example is as such: #!/bin/bash awk '{print first line}' Input.in > Intermediate.ter awk '{print second line}' Input.in > Intermediate_2.ter command Intermediate.ter Intermediate_2.ter > Output.out It works the way I want it to, but it's not... (1 Reply)
Discussion started by: Leo_Boon
1 Replies

6. Homework & Coursework Questions

Calculating Total and Averages with awk Commands & Scripts

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: Write an awk script(company.awk) for the workers file to find the number of workers of each departman, total... (8 Replies)
Discussion started by: RedJohn
8 Replies

7. UNIX for Dummies Questions & Answers

Display Pie Chart/Bar Graph in microsoft outlook email using UNIX commands/Shell scripts

I have a shell script which executes to write html codes into a text file. My next step is to email the text file so that receiving person (people who i send email to) should be able to see pie/chart or bar graph (whatever i design in my code) in their email. Following is the example of a sample... (7 Replies)
Discussion started by: bikerboy
7 Replies

8. UNIX for Beginners Questions & Answers

UNIX commands and scripts

Hi guys, Hoping someone can help with the below - involves basic commands and some scripting. Thanks so much in advance for your amazing time and help. 3. The file /etc/profile contains the default initialization options for your shell. Produce a unique list of all variables with uppercase... (1 Reply)
Discussion started by: edujs7
1 Replies

9. UNIX for Beginners Questions & Answers

Saltstack commands inside bash scripts donā€™t work

In a Redhat Linux environment, I could run salt commands on the $ prompt but not inside my bash scripts. It will say command not found and the $PATH variable is exactly the same outside and inside the script. !#/usr/bin/bash echo “running”¯ salt "*" cmd.run ‘ls' exit Output:-... (8 Replies)
Discussion started by: gurudewa
8 Replies
All times are GMT -4. The time now is 02:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy