|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | 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 and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
break while loop in BASH
Hi gurus, I have the following part of code which I am using for treating input Code:
#!/bin/bash
while [[ $1 = -* ]]; do
arg=$1; shift
case $arg in
-u)
users="$1"
shift
;;
-g)
groups="$1"
shift
;;
-m)
mlength="$1"
shift
;;
-t)
dfileg="$1"
shift
;;
--help)
echo "-m maximum count of characters per line in group file"
echo "for errors see file called: errorlog"
break
;;
*)
break
;;when I issue Code:
./script -u john -g daemon -m 100 -t group everything works fine but when I issue Code:
./script --help the script echos text but did not exit. (I have to interrupt it by ctrl+c) how can I close script after issuing --help ? Thanks a lot |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Change 'break' to 'exit' in the --help case.
|
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Thanks a lot, this helps
BTW is there any more elegant way of treating input ? |
|
#4
|
|||
|
|||
|
Hi wakatana:
I don't think I would go so far as to call it elegant, but there is a standardized utility for dealing with command line options and arguments. getopts It's usually implemented as a shell built-in, so search your shell's man page for 'getopts'. Regards, Alister |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
yes, you should use getopts
|
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to break a loop if condition is met | Issemael | Shell Programming and Scripting | 9 | 07-19-2009 05:59 AM |
| Weird loop break,- please Help | sx3v1l_1n51de | Shell Programming and Scripting | 1 | 07-13-2009 11:24 AM |
| How to break the while loop???(Very Urgent) | sunitachoudhury | Shell Programming and Scripting | 1 | 03-21-2008 04:26 AM |
| ssh break the while loop? | fedora | Shell Programming and Scripting | 5 | 05-23-2007 10:54 AM |
| ksh how user can break out of loop | beckett | Shell Programming and Scripting | 4 | 04-07-2004 06:55 AM |
|
|