1753705 Members
4876 Online
108799 Solutions
New Discussion

Re: shell script help

 
James R. Ferguson
Acclaimed Contributor

Re: shell script help

Hi:

 

No matter which script you like ( and we'll use Dennis's since you reference his ), consider learning a Unix philosophy that says do-one-thing-and-do-it-well.

 

The whole script could be:

 

# cat mymax

#/usr/bin/sh

typeset ca=$1

typeset pa=$2

if (( ca > pa )); then

   echo $ca

else

   echo $pa

fi

 

...which then could be run to output to your terminal:

 

# ./mymax 100 99

100

 

...or to a file:

 

# ./mymax 100 99 > myoutput

 

...or to email:

 

# ./mymax 100 99 | mailx -s "Max Value" mymailaddress

 

The point is to allow the user to determine where he/she wants the output to appear rather than hard-coding that assumption into your script.

 

Regards!

 

...JRF...

1a
Advisor

Re: shell script help

Hi dennis,

 

if the values are equal , how to print the value.

 

 

1a
Advisor

Re: shell script help

hi james R.

thanks for your reply. i want to learn shell script .please send any pdf document or ppt
Dennis Handly
Acclaimed Contributor

Re: shell script help

>if the values are equal, how to print the value.

 

Is this a new question?

Otherwise my script fragment will print the maximum of the two and always prints, even if equal.

If you only want to print if they are equal:

if (( ca == pa )); then

   echo $ca

fi

 

James R. Ferguson
Acclaimed Contributor

Re: shell script help


@1a wrote:

thanks for your reply. i want to learn shell script .please send any pdf document or ppt

I used to recommend the "HP-UX Shell User's Guide" which was a nice overview of the various shells.  With the advent of the "improved" (NOT!) HP websites, this doesn't appear to be available anymore.

 

Regardless, there are any number of good books on shell scripting.  Find one for beginners and begin.  I urge you to confine your initial learning to the Korn ('ksh') or Bash ('bash') shell rather than the dysfunctional C shell.  In HP-UX, the default shell is simply called 'sh' and is a Korn variant.  Bash can also be installed on HP-UX though it is usually the standard for most Linux distributions.

 

Part of learning to write code (in any language) is *writing* and *reading*.  A very good collection of shell scripts is available here:

 

http://www.shelldorado.com/

 

Regards!

 

...JRF...

 

Stephan.
Honored Contributor

Re: shell script help

I only have a pretty old copy of the shell user's guide but it's still a pretty good one.

 

Find it attached.

 

hth,

Stephan