home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!Germany.EU.net!sbsvax!mpi-sb.mpg.de!uwe
- From: uwe@mpi-sb.mpg.de (Uwe Waldmann)
- Newsgroups: comp.unix.shell
- Subject: Re: how to distinguish set command
- Message-ID: <24112@sbsvax.cs.uni-sb.de>
- Date: 25 Jan 93 18:02:20 GMT
- References: <1993Jan23.132103.1@vax1.umkc.edu>
- Sender: news@sbsvax.cs.uni-sb.de
- Reply-To: uwe@mpi-sb.mpg.de
- Organization: Max-Planck-Institut fuer Informatik
- Lines: 45
-
- In article <1993Jan23.132103.1@vax1.umkc.edu>, srinivasan@vax1.umkc.edu writes:
- > I am trying to use the set command in a shell programm file
- > and to my surprise it shows a list of all current shell variables
- > instead of assigning the output of the command that i have given
- > in the back quote. Can someone kindly explain how i can take care
- > of this.
-
- The set command of the Bourne shell has three purposes. If no arguments
- are given, it prints the values of all current shell variables.
- If the first argument(s) start with '-', it sets the options of the shell.
- The remaining arguments are assigned to the positional parameters
- $1, $2, and so on.
-
- If you write
-
- set `somecmd somearg`
-
- to assign the output of somecmd to the positional parameters, two problems
- may occur. First, the output may start with '-', such that the shell
- interprets it as an option. You can use
-
- set -- `somecmd somearg`
-
- to avoid this problem. Second, the output of somecmd may be empty (or
- consist of whitespace characters only). In this case you have two
- possibilities: Either use
-
- set -- "`somecmd somearg`"
-
- which assigns the whole output of somecmd to the first positional parameter
- $1 (including the surrounding whitespace). Alternatively, you can use
- a dummy 'xxx' (so that 'set' has always at least one argument) and shift
- it away afterwards. The command
-
- set xxx `somecmd somearg`
- shift
-
- splits the output of somecmd into words and assigns them, in order,
- to $1, $2, and so on (even if the output is empty). I assume that this
- is what you want.
-
- --
- Uwe Waldmann, Max-Planck-Institut fuer Informatik
- Im Stadtwald, D-W6600 Saarbruecken 1, Germany
- Phone: +49 681 302-5431, Fax: +49 681 302-5401, E-Mail: uwe@mpi-sb.mpg.de
-