View Single Post
  #2   (View Single Post)  
Old 11th June 2021
J65nko J65nko is offline
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,780

Another approach to process the passed arguments is to use "shift". Using the above example:

$1 will contain "King Alfred the Great"
$2 holds the number "1"
$3 holds the number "2"

The special variable "$#" contains the number of arguments.
The situation after a shift:

$1 holds the number "1"
$2 holds the number "2"
and $# will be decreased by one to reflect the number of the remaining parameters.

A script to demonstrate that we can keep printing the first parameter in "$1" when we use shift:
# J65nko -

while [ $# -ne 0 ]; do
    echo  "Parameter $nr :\t$1"
Running with same arguments as in the previous example:
./ "King Alfred the Great" 1 2   
Parameter 1 :   King Alfred the Great
Parameter 2 :   1
Parameter 3 :   2
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote