Skip to main content
added 90 characters in body
Source Link
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

In Bash, ksh93zsh or zsh¹ksh93u+m 1.0.6 or newer¹, you can use the ${parameter/#pattern/string} pattern substitution parameter expansion operator from ksh93 to prepend -l to each array element. You may then redefine your array like this:

array=( "${array[@]/#/-l}" )

Note that if the source was sparse, a relatively uncommon case, this will reset the indexes to 0 through N-1.


¹ yash and mksh also have thatThat operator is initially from ksh93 in 1993, but in current versions, yash doesn'tinitially didn't perform any substitution if the pattern iswas empty. yash and mksh also support that operator but yash still behaves like ksh93 originally and in mksh, it cannot be performed on array expansions.

In Bash, ksh93 or zsh¹, you can use the ${parameter/#pattern/string} pattern substitution parameter expansion operator from ksh93 to prepend -l to each array element. You may then redefine your array like this:

array=( "${array[@]/#/-l}" )

Note that if the source was sparse, a relatively uncommon case, this will reset the indexes to 0 through N-1.


¹ yash and mksh also have that operator, but in current versions, yash doesn't perform any substitution if the pattern is empty and in mksh, it cannot be performed on array expansions.

In Bash, zsh or ksh93u+m 1.0.6 or newer¹, you can use the ${parameter/#pattern/string} pattern substitution parameter expansion operator to prepend -l to each array element. You may then redefine your array like this:

array=( "${array[@]/#/-l}" )

Note that if the source was sparse, a relatively uncommon case, this will reset the indexes to 0 through N-1.


¹ That operator is initially from ksh93 in 1993, but initially didn't perform any substitution if the pattern was empty. yash and mksh also support that operator but yash still behaves like ksh93 originally and in mksh, it cannot be performed on array expansions.

added 69 characters in body
Source Link
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

In Bash, ksh93 or zsh¹, you can use the ${parameter/#pattern/string} pattern substitution parameter expansion operator from ksh93from ksh93 to prepend -l to each array element. You may then redefine your array like this:

array=( "${array[@]/#/-l}" )

Note that if the source was sparse, a relatively uncommon case, this will reset the indexes to 0 through N-1.


¹ yash and mksh also have that operator, but in current versions, yash doesn't perform any substitution if the pattern is empty and in mksh, it cannot be performed on array expansions.

In Bash, ksh93 or zsh¹, you can use the ${parameter/#pattern/string} pattern substitution parameter expansion operator from ksh93 to prepend -l to each array element. You may then redefine your array like this:

array=( "${array[@]/#/-l}" )

Note that if the source was sparse, a relatively uncommon case, this will reset the indexes to 0 through N-1.


¹ yash and mksh also have that operator, but in current versions, yash doesn't perform any substitution if the pattern is empty and in mksh, it cannot be performed on array expansions.

In Bash, ksh93 or zsh¹, you can use the ${parameter/#pattern/string} pattern substitution parameter expansion operator from ksh93 to prepend -l to each array element. You may then redefine your array like this:

array=( "${array[@]/#/-l}" )

Note that if the source was sparse, a relatively uncommon case, this will reset the indexes to 0 through N-1.


¹ yash and mksh also have that operator, but in current versions, yash doesn't perform any substitution if the pattern is empty and in mksh, it cannot be performed on array expansions.

added 332 characters in body
Source Link
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

In Bash, ksh93 or zsh¹, you can use the ${parameter/#pattern/string} pattern substitution parameter expansion operator from ksh93 to prepend -l to each array element. You may then redefine your array like this:

array=( "${array[@]/#/-l}" )

Note that if the source was sparse, a relatively uncommon case, this will reset the indexes to 0 through N-1.


¹ yash and mksh also have that operator, but in current versions, yash doesn't perform any substitution if the pattern is empty and in mksh, it cannot be performed on array expansions.

In Bash, you can use pattern substitution to prepend -l to each array element. You may then redefine your array like this:

array=( "${array[@]/#/-l}" )

Note that if the source was sparse, a relatively uncommon case, this will reset the indexes to 0 through N-1.

In Bash, ksh93 or zsh¹, you can use the ${parameter/#pattern/string} pattern substitution parameter expansion operator from ksh93 to prepend -l to each array element. You may then redefine your array like this:

array=( "${array[@]/#/-l}" )

Note that if the source was sparse, a relatively uncommon case, this will reset the indexes to 0 through N-1.


¹ yash and mksh also have that operator, but in current versions, yash doesn't perform any substitution if the pattern is empty and in mksh, it cannot be performed on array expansions.

added 116 characters in body
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441
Loading
The task involves changing the elements of the array, so show how to assign them to the array after modifying them.
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading
Source Link
Loading