The array tag has no wiki summary.
4
votes
1answer
95 views
Find all users who have more than N processes and echo them in shell
I'm writing a script in ksh. I need to find all users who have more than N processes and echo them in the shell. N is read from ksh.
I know that I should use ps -elf, but how do I parse it, find ...
3
votes
1answer
46 views
How can I remove an element from an array completely?
unset array[0] removes the element but still if I do echo ${array[0]} I get a null value moreover there are other ways of doing this but if an element of an array contains spaces like below
...
3
votes
2answers
129 views
Bash script wait for processes and get return code
I am trying to create a script which will start many background command.
For each background command I need to get the return code.
I have been trying the following script :
#!/bin/bash
set -x
...
3
votes
1answer
71 views
Bash 3.0 not supporting lists?
I have written a small script that add particular IP addresses taken from a config file and then puts it in a list :
WAS_IP=$(grep "<was_ip>" $CONFIG| cut -d '>' -f 2 | cut -d '<' -f 1 ...
5
votes
1answer
63 views
array[@] output all messed up?
I've got this code:
Unix+=("Stock List")
while read line; do
result=$(wget -O - -o /dev/null "http://finance.yahoo.com/d/quotes.csv?s=$line&f=sl1&e=.csv" | tr ',' ' ' | tr '"' ' ')
...
2
votes
1answer
81 views
Zsh style arrays with Bash
Does Bash have a way to access arrays similar to Zsh, something like
$ foo=(dog cat mouse)
$ echo $foo[1]
cat
instead of
$ echo ${foo[1]}
perhaps using some shopt setting?
2
votes
1answer
101 views
Why is not every variable initialized to its data type specific default value upon declaration in Bash?
When I execute the following code in Bash version "GNU bash, version 4.1.10(4)-release (i686-pc-cygwin)", I get:
declare a
declare -p a
# Output: -bash: declare: a: not found
declare -i b
declare -p ...
1
vote
1answer
101 views
How to initialize a read-only, global, associative array in Bash?
I execute the following code in Bash version "GNU bash, Version 4.2.39(1)-release (x86_64-redhat-linux-gnu)":
function foobar {
declare -rgA FOOBAR=([foo]=bar)
}
foobar
declare -p FOOBAR
# Output: ...
5
votes
2answers
208 views
Strange behaviour of uninitialized arrays and unset arrays
I'm writing a script and I discovered some unexpected behaviour of uninitialized and unset array variables that I do not understand.
First of all, the length:
giacomo@jack-laptop:~$ echo ...
3
votes
1answer
238 views
gnuplot shell variable substitution and arrays
I need to use shell variables in my gnuplot commands, for which I'm using the here document style. I also need to use loops inside the gnuplot code. Both these things are working.
Now -- I want to ...
1
vote
2answers
183 views
Auto-expansion problem with array elements containing an '*' (asterisk)
I'm trying to write me a find script that should later be able to read a list of directories to be excluded from an external file. Whilst I can accomplish that part myself, it's the annoying array ...
4
votes
1answer
652 views
What is the most correct way to pass an array to a function?
Consider I have a very large array $large_list, is there a way to write a function that will take the array as an argument? For example:
echo_idx_array () {
arr="$1"
idx="$2"
echo ...
2
votes
4answers
196 views
Loop with 2 variables in a bash script
I am trying to utilize an API. I need to either do some type of "for loop" that replaces or utilizes 2 variables...
In pseudo..
# Declare New Servers
newserver=(
box001
box002
box003
box004
box005
...
5
votes
3answers
862 views
Transform an array into arguments of a command?
I have an array of "options" of a command.
my_array=(option1 option2 option3)
I want to call this command in a bash script, using the values from array as options. So, command $(some magic here ...
3
votes
1answer
55 views
Calling a script on each line of a file
I have a bash script that takes 3 arguments:
$ do_something foo bar baz
and a file with several lines, each with different 3 args.
I want to execute the script as a cronjob, and each time it's ...
3
votes
1answer
183 views
Write default array to variable in Bash
I was expecting
excludes="${excludes:-( ${default_excludes[@]} )}"
to be an array if $excludes is empty. Unfortunately the stuff after :- is taken to be a string. Did I miss some syntax contortion, ...
1
vote
0answers
254 views
Array Performance very similar to LinkedList - What gives? [closed]
So the title is somewhat misleading... I'll keep this simple: I'm comparing these two data structures:
An array, whereby it starts at size 1, and for each subsequent addition, there is a realloc() ...
2
votes
1answer
640 views
Array of string expanded to path?
Suppose I have the following initialization of bash array:
my_array=(
"/usr/bin"
"/usr/lib/*.so"
)
If I do iteration using:
for array_item in ${my_array[@]}
do
...
done
Then the ...
1
vote
3answers
1k views
Bash eval array variable name
Here is my bash case:
First case, this is what I want to do "aliasing" var with myvarA:
myvarA="variableA"
varname="A"
eval varAlias=\$"myvar"$varname
echo $varAlias
Second case for array variable ...