All Questions
10 questions
1
vote
1
answer
861
views
How to define arrays in zsh with user supplied key names
I just started using zsh and I can't figure out how to define arrays with user defined keys.
(I'm following the documentations on arrays: http://zsh.sourceforge.net/Doc/Release/Parameters.html#Array-...
23
votes
4
answers
33k
views
How to iterate over array indices in zsh?
In bash we can iterate over index of an array like this
~$ for i in "${!test[@]}"; do echo $i; done
where test is an array, say,
~$ test=(a "b c d" e f)
so that the output looks ...
3
votes
2
answers
1k
views
Assign $@ to another variable in a shell function
I'm making an intelligent alias gc that can differentiate git commit/checkout.
If gc is called without any arguments or with the -a, -m arguments, then git commit is run. Otherwise, git checkout is ...
0
votes
1
answer
814
views
More efficient zsh string parsing / array handling
Is there any more efficient way to do the following in zsh?
I imagine that there might be ways to get rid of the intermediate array parameters a and/or b.
The script gets some output from a command. ...
6
votes
1
answer
3k
views
Split zsh array from subshell by linebreak
I would like to instantiate a zsh array from a subshell
myarray=($(somecommand)
and I check if I received what I wanted with
for element in $myarray ; do echo "===" ; echo $element ; echo "---" ; ...
6
votes
1
answer
898
views
Assigning a new value directly into a character index of a value in an array with zsh
If I have an array of strings and I want to change a single character in one value I could do this:
$ array=(hello world)
$ array[2]=${array[2]:0:2}X${array[2]:3}
$ echo $array[2]
woXld
Even though ...
4
votes
4
answers
3k
views
zsh: map command to array
suppose you have an array a=(foo 'bar baz')
is there a more obvious way to apply a command/function to every array element and save the resulting strings into another array than this:
b=()
for e in $...
1
vote
1
answer
1k
views
Zsh script how to concatanate array elements with string
I have written a zsh script to automize an analysis in high energy physics and now I would like to use an element of the one of the defined array some string and another element of some another array ...
0
votes
1
answer
489
views
Cannot access elements of an array in zsh
I am trying to write a script in zsh and I need to make use of arrays in order to achieve my aim in an elegant way. After reading some information over the Net, I tried to implement and access the ...
8
votes
3
answers
5k
views
${#array} vs ${#array[@]}
As far as I can tell both ${#array[@]} and ${#array} evaluate to the number of elements in $array. Is there any reason for preferring the longer form (${#array[@]})?