help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] View Positional Parameters of Commands


From: Michael Convey
Subject: Re: [Help-bash] View Positional Parameters of Commands
Date: Tue, 28 Jul 2015 18:10:05 -0700

​​
On Tue, Jul 28, 2015 at 8:12 AM, Clark Wang <address@hidden> wrote:

> For example:
>

>   $ foo() { echo $0 $1 $2; }
>   $ foo
>   /Users/clarkw/utils/bin/bash
>   $ foo -a
>   /Users/clarkw/utils/bin/bash -a
>   $ foo -al
>
> ​​
> /Users/clarkw/utils/bin/bash -al
>   $ foo -al bar
>
> ​​
> /Users/clarkw/utils/bin/bash -al bar
>   $
>

​​Excellent example thank you. I'm still unclear why the output of your
last command is,

​
​
​
 /Users/clarkw/utils/bin/bash -al bar
​
​instead of,

foo ​-al bar
?

​
​

On Tue, Jul 28, 2015 at 11:12 PM, Clark Wang <address@hidden> wrote:​

Or you can change current shell's $*N* like this:

  # echo "<$0> <$1> <$2>"
  </Users/clarkw/utils/bin/bash> <> <>
  # set -- -a
  # echo "<$0> <$1> <$2>"
  </Users/clarkw/utils/bin/bash> <-a> <>
  # set -- -al
  # echo "<$0> <$1> <$2>"
  </Users/clarkw/utils/bin/bash> <-al> <>
  # set -- -al bar
  #
​​
echo "<$0> <$1> <$2>"
  </Users/clarkw/utils/bin/bash> <-al> <bar>
  #


Fascinating! Why doesn't this work?

​$ foo() { echo $0 $1 $2 $3 $4; }
$ foo -a -b -c
bash -a -b -c
$
​
echo "<$0> <$1> <$2>"
bash <> <>

Is it because 'foo()' is run in a subshell and 'echo "<$0> <$1> <$2>"' is
run in the parent shell? If so, then the set command is not run in a
subshell, right?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]