Re: *nix advice for assignment
From: Rich Gibbs (richg74_at_REMOVEgmailCAPS.com)
Date: 11/10/05
- Next message: Greg: "Read line at at time and split up that line"
- Previous message: Ed Morton: "Re: Compare 2 sorted list , Print values present in list 1 only"
- In reply to: nutshell: "*nix advice for assignment"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 10 Nov 2005 11:41:50 -0500
nutshell said the following, on 11/10/05 00:56:
> First off, I am taking a *nix class and trying to write my own script
> but I need to verify the following. I imagine my classmates are lookig
> around the same groups so please do not tell me the answer but only
> verify the commands I have written below.
>
>
Thank you for being honest that this is an assignment.
> 1. How can you tell if a command successfully completed? What
> shell-maintained variable would you use? Give an example.
>
> MY ANSWER: history -ps argument
>
The key here is "shell-maintained variable". There is a specific
mechanism in the shell that is meant to give access to the return code
from a command. Look through your documentation for "(pre-defined)
shell variables", or something similar.
> 2. Write a shell script that takes in any number of command line
> arguments, but quits when a zero (0) is found.
>
> Example:
>
> Q2.sh 1 2 3 0 4 5 6 t y u i i
>
> Q2.sh should echo out each command line argument, and quits when a zero
> is found. Also, echo out that it is exiting because the zero was
> detected.
>
> MY ANSWER: this will be an if-else statement, right?
>
It may involve an if-else, but the key to getting the answer is to think
about how to access the arguments (1, 2, 3, 0, 4, ... in the example) in
sequence.
-- Rich Gibbs richg74@gmail.com "You can observe a lot by watching." -- Yogi Berra
- Next message: Greg: "Read line at at time and split up that line"
- Previous message: Ed Morton: "Re: Compare 2 sorted list , Print values present in list 1 only"
- In reply to: nutshell: "*nix advice for assignment"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|