home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!lll-winken!elroy.jpl.nasa.gov!decwrl!deccrl!bloom-beacon!eru.mt.luth.se!lunic!sunic!mcsun!uknet!siesoft!wstuart!stuart
- From: stuart@wstuart (Stuart Hood)
- Newsgroups: comp.unix.shell
- Subject: Help: how to keep spaces in args
- Summary: How do I maintain an argument with spaces in
- Keywords: sh, getopt
- Message-ID: <1992Aug19.153607.8593@siesoft.co.uk>
- Date: 19 Aug 92 15:36:07 GMT
- Sender: news@siesoft.co.uk (Usenet News)
- Organization: Siemens Nixdorf Information Systems Ltd.
- Lines: 51
- X-Newsreader: Tin 1.1 PL4
-
- Basically I want the following program to output "Hi there",
- rather than just "Hi"
-
- Script started on Wed Aug 19 14:07:35 1992
- $ cat t
- #!/bin/sh
-
- set -- `getopt a:b "$@"`
-
- while test $# -gt 0
- do
- case $1 in
- -a)
- echo $2
- shift 2
- ;;
- -b)
- shift
- ;;
- *)
- shift
- ;;
- esac
- done
- $ ./t -a "Hi there"
- Hi
- $
- script done on Wed Aug 19 14:08:00 1992
-
- Adding an "eval" to the "set" line doesn't help because
- "getopt" doesn't out put any quote characters around its
- arguments.
-
- I can think of 2 hacks to get round this:
-
- - have the "-a" case grab in all arguments until it reaches
- another option.
- - replace all spaces in the arguments with, say, '!' before
- doing the getopt and then restore them when needed.
-
- I don't like either of these solutions, can anyone suggest
- a better solution?
-
- Thanks in advance for any help,
-
- Stuart.
- -
- --
- S I E M E N S Stuart Hood === Siemens Nixdorf House, Bracknell, Berks, UK
- ------------- Phone: + 44-344-850892 Email: stuart@siesoft.co.uk
- N I X D O R F - Never let ignorance stand in the way of a good argument -
-