![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
|||
|
-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. |
|
|||
|
Quote:
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. |