Skip to main content
Please don't edit my questions after 7 years.
Source Link
3kstc
  • 5.1k
  • 16
  • 37
  • 49

With myarray that containsIf I have an array with 5 elements, I can usefor example:

[a][b][c][d][e]

Using echo ${myarray[4]} to access the last itemI can see what it holds.

What can I do whenBut what if I don'tdidn't know the number of array elements in a given array? Is there a way of reading the last element of an unknown length array? i.e. The first element reading from the right to the left for any array?

I would like to know how to do this with Bashin bash.

With myarray that contains an array with 5 elements, I can use ${myarray[4]} to access the last item.

What can I do when I don't know the number of array elements?

I would like to know how to do this with Bash.

If I have an array with 5 elements, for example:

[a][b][c][d][e]

Using echo ${myarray[4]} I can see what it holds.

But what if I didn't know the number of elements in a given array? Is there a way of reading the last element of an unknown length array? i.e. The first element reading from the right to the left for any array?

I would like to know how to do this in bash.

If I haveWith myarray that contains an array with 5 elements, for example:

[a][b][c][d][e]

UsingI can use echo ${myarray[4]} I can see what it holdsto access the last item.

But what ifWhat can I didn'tdo when I don't know the number of elements in a given array? Is there a way of reading the last element of an unknown length array? i.e. The first element reading from the right to the left for any array elements?

I would like to know how to do this in bashwith Bash.

If I have an array with 5 elements, for example:

[a][b][c][d][e]

Using echo ${myarray[4]} I can see what it holds.

But what if I didn't know the number of elements in a given array? Is there a way of reading the last element of an unknown length array? i.e. The first element reading from the right to the left for any array?

I would like to know how to do this in bash.

With myarray that contains an array with 5 elements, I can use ${myarray[4]} to access the last item.

What can I do when I don't know the number of array elements?

I would like to know how to do this with Bash.

Tweeted twitter.com/StackUnix/status/1173748497704730629
added 6 characters in body; edited title
Source Link
Mat
  • 54.9k
  • 11
  • 164
  • 143

Is there a way of reading the last argumentelement of an array with bash?

If I have an array with 5 elements, for example:

[a][b][c][d][e]

byUsing echo ${myarray[4]} I can see what it holds.

But what if I didn't know the number of elements in a given array.? Is there a way of reading the last element of an unknown length array? iei.e. The first element reading from the right to the left for any array?!

I would like to know how to do this in BASHbash.

Is there a way of reading the last argument of an array with bash?

If I have an array with 5 elements for example

[a][b][c][d][e]

by echo ${myarray[4]} I can see what it holds.

But what if I didn't know the number of elements in a given array. Is there a way of reading the last element of an unknown length array? ie The first element reading from the right to the left for any array?!

I would like to know how to do this in BASH

Is there a way of reading the last element of an array with bash?

If I have an array with 5 elements, for example:

[a][b][c][d][e]

Using echo ${myarray[4]} I can see what it holds.

But what if I didn't know the number of elements in a given array? Is there a way of reading the last element of an unknown length array? i.e. The first element reading from the right to the left for any array?

I would like to know how to do this in bash.

Source Link
3kstc
  • 5.1k
  • 16
  • 37
  • 49
Loading