The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 06:28 AM
Need a little assistance with a shell script rickou812 Shell Programming and Scripting 3 02-04-2008 04:18 AM
I need an assistance mytilini boy Shell Programming and Scripting 1 05-25-2007 08:42 PM
Perl script assistance; paste word into external command bru Shell Programming and Scripting 10 02-23-2007 04:04 AM
Interpreting a script line by line assistance mdpgc Shell Programming and Scripting 0 02-21-2007 11:57 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-07-2007
Brusimm Brusimm is offline
Registered User
  
 

Join Date: May 2007
Location: Bay Area, CA
Posts: 3
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 07:54 AM..
  #2 (permalink)  
Old 05-08-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
-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.
  #3 (permalink)  
Old 05-10-2007
Brusimm Brusimm is offline
Registered User
  
 

Join Date: May 2007
Location: Bay Area, CA
Posts: 3
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-10-2007 at 01:43 AM..
  #4 (permalink)  
Old 05-10-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0