Skip to main content
edited body; edited title
Source Link
peterh
  • 10.5k
  • 18
  • 70
  • 99

how How to get bash indexes of parameters array?

iI want indexes of parameters,

and can get it by dummy var:

dummy=( $@ )
echo ${!dummy[@]}

but is there straight way to get them, something like

$!@ ... not working
$!* ... not working

... or something like that?

NOTE: original function that i want to have without arr var is this:

function indexof()
{  search="$1"; shift; arr=( $@ ) 
   for i in "${!arr[@]}"; do [ "$search" == "${arr[$i]}" ] && return $i; done
   return -1
}

how to get bash indexes of parameters array

i want indexes of parameters,

and can get it by dummy var:

dummy=( $@ )
echo ${!dummy[@]}

but is there straight way to get them, something like

$!@ ... not working
$!* ... not working

... or something like that?

NOTE: original function that i want to have without arr var is this:

function indexof()
{  search="$1"; shift; arr=( $@ ) 
   for i in "${!arr[@]}"; do [ "$search" == "${arr[$i]}" ] && return $i; done
   return -1
}

How to get bash indexes of parameters array?

I want indexes of parameters,

and can get it by dummy var:

dummy=( $@ )
echo ${!dummy[@]}

but is there straight way to get them, something like

$!@ ... not working
$!* ... not working

... or something like that?

NOTE: original function that i want to have without arr var is this:

function indexof()
{  search="$1"; shift; arr=( $@ ) 
   for i in "${!arr[@]}"; do [ "$search" == "${arr[$i]}" ] && return $i; done
   return -1
}
added 254 characters in body
Source Link
Asain Kujovic
  • 2.2k
  • 1
  • 20
  • 24

i want indexes of parameters,

and can get it by dummy var:

dummy=( $@ )
echo ${!dummy[@]}

but is there straight way to get them, something like

$!@ ... not working
$!* ... not working

... or something like that?

NOTE: original function that i want to have without arr var is this:

function indexof()
{  search="$1"; shift; arr=( $@ ) 
   for i in "${!arr[@]}"; do [ "$search" == "${arr[$i]}" ] && return $i; done
   return -1
}

i want indexes of parameters,

and can get it by dummy var:

dummy=( $@ )
echo ${!dummy[@]}

but is there straight way to get them, something like

$!@ ... not working
$!* ... not working

... or something like that?

i want indexes of parameters,

and can get it by dummy var:

dummy=( $@ )
echo ${!dummy[@]}

but is there straight way to get them, something like

$!@ ... not working
$!* ... not working

... or something like that?

NOTE: original function that i want to have without arr var is this:

function indexof()
{  search="$1"; shift; arr=( $@ ) 
   for i in "${!arr[@]}"; do [ "$search" == "${arr[$i]}" ] && return $i; done
   return -1
}
Source Link
Asain Kujovic
  • 2.2k
  • 1
  • 20
  • 24

how to get bash indexes of parameters array

i want indexes of parameters,

and can get it by dummy var:

dummy=( $@ )
echo ${!dummy[@]}

but is there straight way to get them, something like

$!@ ... not working
$!* ... not working

... or something like that?