The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need assistance ----SH schell script shahidbakshi Shell Programming and Scripting 2 02-22-2008 02:28 AM
Need a little assistance with a shell script rickou812 Shell Programming and Scripting 3 02-04-2008 12:18 AM
I need an assistance mytilini boy Shell Programming and Scripting 1 05-25-2007 05:42 PM
Perl script assistance; paste word into external command bru Shell Programming and Scripting 10 02-23-2007 12:04 AM
Interpreting a script line by line assistance mdpgc Shell Programming and Scripting 0 02-21-2007 07:57 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-07-2007
Registered User
 

Join Date: May 2007
Location: Bay Area, CA
Posts: 3
Stumble this Post!
KSH Script Assistance

Hey everyone, I'm newer than new when it comes to this ksh and scripting stuff, and unix in general. I have been thrown into a task at work that
A: They expect me to come up to speed on,
B: Show I can do this. (Program for the workgroup)

Here's the script, part of it, from the overall script:

if [ $# -eq 1 ]; then
echo "the files that exist...... ...."
FILEDIR="$1"
elif [ $# -eq 2 ]; then
echo "The files exist in $1/$2..... .... "
FILEDIR="$1"
SUBDIR="$2"
else
echo "Script help text"
echo "script filedir [subdir]
echo " "
exit 1
fi.

OK, here's what I know/understand:
I can type the script name, followed by one or 2 paramaters that it will see, and work on. Or, if no parameters are entered, we get that help screen. So far, so .. so.
I also see where $1 and $2 are assigned to parameters or variables, depending on when they are typed.

My task (At the moment) is to add a '-h' option to bring up the help text rather than let it run when no parameters are supplied. I don't know or have figured out how, despite reading through a few books today because I'm not sure what I am looking for precisely.

My first issue is I do not understand the '$#' or the '-eq'.
My second issue is how deep can if's be nested? (If that's where I need to go with this one.)

Any help would be appreciated. AND If anyone can point me to good resources on the web to review or learn from for future reference? I need to learn what I'm looking at so I don't have to ask help for what seems to be simple questions.

Thanks!

Last edited by Brusimm; 05-09-2007 at 04:54 AM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-08-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,795
Stumble this Post!
-eq means equal (integer), -lt less than, -gt greater than, etc.
You can nest if statements.

$0, $1, $2,...$9, $#, and $* are defined by the shell itself. $# is the number of parms.

What you probably want is getopts. It is used for things like -h.
Reply With Quote
  #3 (permalink)  
Old 05-09-2007
Registered User
 

Join Date: May 2007
Location: Bay Area, CA
Posts: 3
Stumble this Post!
Quote:
Originally Posted by jim mcnamara
-eq means equal (integer), ......
What you probably want is getopts. It is used for things like -h.
Thanks Jim....

Would I use the getopts in place of the structure I have here, or add in after the code I've got?

Last edited by Brusimm; 05-09-2007 at 10:43 PM.
Reply With Quote
  #4 (permalink)  
Old 05-10-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,425
Stumble this Post!
Quote:
Originally Posted by Brusimm
My second issue is how deep can if's be nested?
There is no arbitrary limit. But at 10 to 15 the code would hard for a human to read so you don't want to over-do it. Search for getopts on this site and you will find plenty of scripts that use it.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0