New answers tagged

0 votes

Bash - reverse an array

Two different versions Inspired from Cyrus's answer and wiki.wooledge.org. Very quick as there are no loop and no forks! And here, confined into one single function. Print submited array in reversed ...
3 votes
Accepted

Bash create parameter named array within function

You'd use a nameref for that: writeToArray() { local -n writeToArray_name="$1" writeToArray_name[0]="does this work?" } Testing: bash-5.0$ test[123]=qwe bash-5.0$ ...
2 votes

Special array from list of items in current dir

With zsh instead of bash: array=() n=0 for f ( $dir/*(N-/) ) array+=( $((++n)) $f:t 'is a dir' ) for f ( $dir/*.ext1(N^-/) ) array+=( $((++n)) $f:t 'is a ext1 non-directory file' ) Note that in zsh, ...
3 votes
Accepted

Special array from list of items in current dir

There's no need to parse ls. Remember to double-quote each time you use your variables such as "$line", otherwise it will be subject to splitting on $IFS (typically whitespace) and globbing. ...
  • 101k

Top 50 recent answers are included