[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: punkte zählen



On Tue, Feb 14, 2006 at 06:03:13PM +0000, Joerg Sommer wrote:
> Für mein Verständnis ist der zweite Teil (A=...) kein Kommando sondern
> eine Variablenzuweisung. 

Die Shell verarbeitet nach dem Parsen und Expandieren einfach Listen von
"commands". Und ein "command" kann sowohl eine Zuweisung als auch ein
Aufruf wie "ls" sein. Eine Syntax der klassischen Bourne-Shell gibt's in
einer klassischen Intro von Stephen Bourne selbst. Online z.B. unter
http://steve-parker.org/sh/bourne.shtml

Stephen Bourne sagt in dem Paper im Abschnitt "3.0 Keyword paramaters":

  Shell variables may be given values by assignment or when a shell
  procedure is invoked. An argument to a shell procedure of the form
  name=value that precedes the command name causes value to be assigned to
  name before execution of the procedure begins. The value of name in the
  invoking shell is not affected. For example,

    user=fred command

  will execute command with user set to fred. The -k flag causes arguments
  of the form name=value to be interpreted in this way anywhere in the
  argument list. Such names are sometimes called keyword parameters. If any
  arguments remain they are available as positional parameters $1, $2, ....

Offensichtlich handhaben das die modernen Varianten der Bourne-Shell immer
noch so. Die Manpage der Bash sagt bei mir dazu:

  The environment for any simple command or function may be augmented
  temporarily by prefixing it with parameter assignments, as described
  above in PARAMETERS. These assignment statements affect only the
  environment seen by that command.

  If the -k option is set (see the set builtin command below), then all
  parameter assignments are placed in the environment for a command, not
  just those that precede the command name.

> greifen. Andernfalls müsste auch "IFS=. set $A" funktionieren, was es bei
> mir nicht tut.

In diesem Fall ist IFS=. ja kein Keyword-Parameter, sondern Bestandteil des
Strings selbst. Und der evaluiert letzten Endes nicht zu einem gueltigen
"command":

lilith[1628]: bash
[jc@lilith jc]$ A=foo.bar.baz
[jc@lilith jc]$ "IFS=. set $A"
bash: IFS=. set foo.bar.baz: command not found

	--jc

-- 
  In zweifelhaften Fällen entscheide man sich für das Richtige.
	-- Karl Kraus (1874-1936) 



Reply to: