New answers tagged array
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$ ...
- 504k
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, ...
- 504k
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
Related Tags
array × 616bash × 412
shell-script × 171
shell × 57
awk × 53
zsh × 42
variable × 39
text-processing × 26
string × 26
linux × 24
scripting × 24
bash-array × 23
for × 20
function × 18
grep × 16
csv × 15
ksh × 15
associative-array × 14
arguments × 13
sed × 12
quoting × 12
sort × 12
parameter × 11
files × 10
read × 10