home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / shell / 5494 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  2.1 KB

  1. Path: sparky!uunet!mcsun!Germany.EU.net!sbsvax!mpi-sb.mpg.de!uwe
  2. From: uwe@mpi-sb.mpg.de (Uwe Waldmann)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: how to distinguish set command
  5. Message-ID: <24112@sbsvax.cs.uni-sb.de>
  6. Date: 25 Jan 93 18:02:20 GMT
  7. References: <1993Jan23.132103.1@vax1.umkc.edu>
  8. Sender: news@sbsvax.cs.uni-sb.de
  9. Reply-To: uwe@mpi-sb.mpg.de
  10. Organization: Max-Planck-Institut fuer Informatik
  11. Lines: 45
  12.  
  13. In article <1993Jan23.132103.1@vax1.umkc.edu>, srinivasan@vax1.umkc.edu writes:
  14. >     I am trying to use the set command in a shell programm file
  15. > and to my surprise it shows a list of all current shell variables 
  16. > instead of assigning the output of the command that i have given
  17. > in the back quote. Can someone kindly explain how i can take care 
  18. > of this.
  19.  
  20. The set command of the Bourne shell has three purposes.  If no arguments
  21. are given, it prints the values of all current shell variables.
  22. If the first argument(s) start with '-', it sets the options of the shell.
  23. The remaining arguments are assigned to the positional parameters
  24. $1, $2, and so on.
  25.  
  26. If you write
  27.  
  28.   set `somecmd somearg`
  29.  
  30. to assign the output of somecmd to the positional parameters, two problems
  31. may occur.  First, the output may start with '-', such that the shell
  32. interprets it as an option.  You can use
  33.  
  34.   set -- `somecmd somearg`
  35.  
  36. to avoid this problem.  Second, the output of somecmd may be empty (or
  37. consist of whitespace characters only).  In this case you have two
  38. possibilities:  Either use
  39.  
  40.   set -- "`somecmd somearg`"
  41.  
  42. which assigns the whole output of somecmd to the first positional parameter
  43. $1 (including the surrounding whitespace).  Alternatively, you can use
  44. a dummy 'xxx' (so that 'set' has always at least one argument) and shift
  45. it away afterwards.  The command
  46.  
  47.   set xxx `somecmd somearg`
  48.   shift
  49.  
  50. splits the output of somecmd into words and assigns them, in order,
  51. to $1, $2, and so on (even if the output is empty).  I assume that this
  52. is what you want.
  53.  
  54. -- 
  55. Uwe Waldmann, Max-Planck-Institut fuer Informatik
  56. Im Stadtwald, D-W6600 Saarbruecken 1, Germany
  57. Phone: +49 681 302-5431, Fax: +49 681 302-5401, E-Mail: uwe@mpi-sb.mpg.de
  58.