Re: *nix advice for assignment

From: Rich Gibbs (richg74_at_REMOVEgmailCAPS.com)
Date: 11/10/05


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


Relevant Pages

  • Re: checking return code for background process
    ... returns zero. ... Use the 'wait' command, or write the background job to store $? ... /tmp> echo $? ... The shell does not ...
    (comp.unix.shell)
  • Re: *nix advice for assignment
    ... > verify the commands I have written below. ... How can you tell if a command successfully completed? ... but quits when a zero is found. ... echo out that it is exiting because the zero was ...
    (comp.unix.shell)
  • Re: Script Help
    ... It finds the exit status of the previous command. ... is "Zero it means the command has executed without any errors else it ... % echo $? ...
    (comp.unix.shell)
  • Re: if branch .. whats wrong??
    ... A zero return status of a command is true. ... You aren't using $i, but you test it, and this is a command. ... Moreover, if you just, the result is true regardless of the value of i. ... bash-3.00$ echo $? ...
    (comp.unix.shell)
  • Re: Persisting env vars in cmd windows
    ... more about batch files as you go on, ... echo The time is %time::=.% ... But the piece de resistance was the "start" command, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)