Current-Users archive

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

Re: Shell confusion over positional arguments?



    Date:        Mon, 10 Mar 2025 09:07:44 -0700
    From:        Brian Buhrow <buhrow%nfbcal.org@localhost>
    Message-ID:  <202503101607.52AG7i3X023248%nfbcal.org@localhost>

  | #!/bin/sh
  | # Test retrieving command arguments by using numeric values.
  |
  | arg1=$1
  | arg2=$2
  | arg3=$3
  | arg4=$4
  | arg5=$5
  | arg6=$6
  | arg6=$6
  | arg7=$7
  | arg8=$8
  | arg9=$9
  | arg10=$10
  | arg10=$10
  | arg11=$11

This is a simple one, $10 is $1 followed by a '0' - old NetBSD shells
used to get it wrong, and treat that as the 10th arg, that was simply
a bug that was fixed somewhere in the netbsd7 or netbsd8 timeframe.

To reference positional args > $9 you need to use braces ${10} etc.
That is, without the braces, only a single digit is treated as the
parameter identifier.

That's always been the rule.   There were lots of bugs in our shell that
long ago (and earlier, of course).

kre


Home | Main Index | Thread Index | Old Index