Wednesday, 24 January 2024

bash script positional arguments

https://hbctraining.github.io/Training-modules/Intermediate_shell/lessons/positional_params.html 

Here we can see that our command is the first positional parameter ($0) and that each of the strings afterwards are additional positional parameters (here $1 and $2). Generally when we refer to positional parameters we ignore $0 and start with $1.

It is crucial to note that different positional parameters are separated by whitespace and can be strings of any length. This means that:

$ ./myscript.sh OneTwoThree

has only given one positional parameter $1=OneTwoThree

and

$ ./myscript.sh O N E

has given three positional parameters $1=O $2=N $3=E

No comments:

Post a Comment