home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3528 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  1.6 KB

  1. 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
  2. From: stuart@wstuart (Stuart Hood)
  3. Newsgroups: comp.unix.shell
  4. Subject: Help: how to keep spaces in args
  5. Summary: How do I maintain an argument with spaces in
  6. Keywords: sh, getopt
  7. Message-ID: <1992Aug19.153607.8593@siesoft.co.uk>
  8. Date: 19 Aug 92 15:36:07 GMT
  9. Sender: news@siesoft.co.uk (Usenet News)
  10. Organization: Siemens Nixdorf Information Systems Ltd.
  11. Lines: 51
  12. X-Newsreader: Tin 1.1 PL4
  13.  
  14. Basically I want the following program to output "Hi there",
  15. rather than just "Hi"
  16.  
  17. Script started on Wed Aug 19 14:07:35 1992
  18. $ cat t
  19. #!/bin/sh
  20.  
  21. set -- `getopt a:b "$@"`
  22.  
  23. while test $# -gt 0
  24. do
  25.     case $1 in
  26.         -a)
  27.             echo $2
  28.             shift 2
  29.             ;;
  30.     -b)
  31.         shift
  32.         ;;
  33.         *)
  34.             shift
  35.             ;;
  36.     esac
  37. done
  38. $ ./t -a "Hi there"
  39. Hi
  40. script done on Wed Aug 19 14:08:00 1992
  41.  
  42. Adding an "eval" to the "set" line doesn't help because
  43. "getopt" doesn't out put any quote characters around its
  44. arguments.
  45.  
  46. I can think of 2 hacks to get round this:
  47.  
  48. - have the "-a" case grab in all arguments until it reaches
  49.   another option.
  50. - replace all spaces in the arguments with, say, '!' before
  51.   doing the getopt and then restore them when needed.
  52.  
  53. I don't like either of these solutions, can anyone suggest
  54. a better solution?
  55.  
  56. Thanks in advance for any help,
  57.  
  58. Stuart.
  59. -
  60. --
  61. S I E M E N S  Stuart Hood === Siemens Nixdorf House, Bracknell, Berks, UK
  62. -------------  Phone: + 44-344-850892          Email: stuart@siesoft.co.uk
  63. N I X D O R F  - Never let ignorance stand in the way of a good argument -
  64.