I was reading about positional parameters in Unix and then I found this info:
The shell allows a command line to contain at least 128 arguments; however, a shell program is restricted to referencing only nine positional parameters, $1 through $9, at a given time. You can work around this restriction by using the shift command.
So I created a simple shell script called file
like the following:
#! /bin/bash
echo $14
then ran it like the following :
./file 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
and I got 14!
So how is that possible if the shell doesn't allow more than 10 parameters (from $0 to $9) without using shift
command?
./file a b c d e f g h i j k l m n o
– steeldriver Jan 25 '21 at 01:56${ }
(tryecho "${14}"
). – Gordon Davisson Jan 25 '21 at 02:16${14}
(or${014}
). The OP is reading outdated documentation. – Jan 25 '21 at 07:38dash -c 'echo ${100000}' - {1..99999} xxx
givesxxx
. I wouldn't say it works fine with Bash though, on Bash 4.4. it takes ages to start when given so many args. – ilkkachu Jan 25 '21 at 11:06