home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!caen!malgudi.oar.net!chemabs!lwv26
- From: lwv26@cas.org (Larry W. Virden)
- Subject: ksh: how to properly parse through arguments?
- Message-ID: <1992Sep1.194057.13966@cas.org>
- Followup-To: comp.unix.shell
- Sender: usenet@cas.org
- Reply-To: lvirden@cas.org (Larry W. Virden)
- Organization: Nedriv Software and Shoe Shiners, Uninc.
- References: <1992Aug28.051548.16935@ddsw1.mcs.com> <ahn.714982174@ac> <1992Sep1.190410.17063@prism.poly.edu>
- Date: Tue, 1 Sep 1992 19:36:05 GMT
- Lines: 51
-
-
- Okay. I have some code which has to read thru its arguments. These arguments
- may have quotes, definitely have spaces, etc.
-
- I have to look thru them, acting on certain flags and then pass the rest
- off to another program.
-
- I have code like:
-
-
- arg=""
- while [ "$#" -gt 0 ] ; do
- case "$1" in
-
- -Q )
- echo "time to go fishing"
- shift
- ;;
- -X )
- echo "Who knows?"
- shift
- ;;
-
- * )
- arg="$arg $1"
- shift
- ;;
- esac
- done
-
- other_cmd $arg
- exit
-
- The problem is that last line. If I use that, then arguments which have
- embedded blanks turn into separate words - not good.
-
- If I make the line:
-
- other_cmd "$arg"
-
- then all the flags become one argument - not good.
-
- If I try to put quotes around the arg="$arg \"$1\"" they seem to disappear
- before other_cmd get the arguments.
-
- What trick do I need here?
- --
- Larry W. Virden UUCP: osu-cis!chemabs!lvirden
- Same Mbox: BITNET: lvirden@cas INET: lvirden@cas.org
- Personal: 674 Falls Place, Reynoldsburg, OH 43068-1614
- America Online: lvirden@aol.com
-