All Questions
18 questions
0
votes
1
answer
125
views
Bash create parameter named array within function
I'm attempting to write a function that writes arrays with a name that's passed in. Given the following bash function:
function writeToArray {
local name="$1"
echo "$name"
...
-1
votes
2
answers
503
views
Redirect a part of mapfile function to stdout but not into the array
Summary: Like we have Stdout Stderr, I would like to create Stdstatus. Stdout can be stored in array and Stdstatus can be printed for user. I didn't know that stderr could be used for other messages ...
1
vote
1
answer
155
views
appending values in a dynamic array
#!/bin/bash
range=$(seq -f "cen%04g" 1052 1099)
range1=$(seq -f "rh%04g" 1052 1099)
check () {
for node1 in ${range};do
ping -q -c 1 -w 3 -s 10 $node1 >/dev/null
if [ ...
1
vote
2
answers
1k
views
Got bad array subscript when wring a function printing the fibonacci numbers
This is my code to write a function which prints the Fibonacci numbers
function fib {
fib_array=( 0 1 )
count=3
while [[ $count -le $1 ]]
do
fib_new=$...
0
votes
1
answer
232
views
Awk function, syntax error near unexpected 'myArr,'
I am not sure why my simple function causes "Syntax error near unexpected 'myArr,'. I taking an array, lookup key value and a line item section name as arguments. Each row in the array is "," ...
8
votes
2
answers
4k
views
What's the idiomatic way of returning an array in a zsh function?
I have this function,
rpargs () {
local i
args=()
for i in "$@"
do
test -e "$i" && args+="$(realpath --canonicalize-existing -- "$i")" || args+="$i"
done
}
And I ...
3
votes
3
answers
5k
views
Generic function to loop over inputs and execute a command in bash?
I was trying to create a function that loops over inputs and executes a command - regardless of how they are delimited.
function loop {
# Args
# 1: Command
# 2: Inputs
for ...
3
votes
2
answers
405
views
Add to array only within scope of function
I'm writing a function that will make a REST API calls which could be either GET, PUT, DELETE, POST, etc.
I would like to feed this method to the function as a parameter and add it to the options ...
0
votes
1
answer
373
views
Shell Function: Sequence of Pipelines as Argument
I have a shell function (in .bashrc) which creates a temp file, executes the arguments (including all sequence of pipelines), redirects it to a temp file and then open it in VS Code.
I invoke the ...
2
votes
3
answers
4k
views
bash array with space in element [closed]
I have a text log file
$ cat aaa
673 20160405 root "/path_to/gis/20160401/20160301_placement_map_org.dbf" ""
673 20160405 root "/path_to/gis/20160401/...
2
votes
1
answer
272
views
Detect optional function argument (array)
Consider this function:
function add_one(in_ar, each) {
for (each in in_ar) {
in_ar[each]++
}
}
I would like to modify it such that if a second array is provided, it would be
used instead ...
4
votes
2
answers
1k
views
Zsh, Indirect array variable assignment without using eval
I have a variable VARNAME which contains a name of another variable. I'd like to assign to this another variable without using eval. How can I do that?
Th reason I don't want to use eval is the ...
2
votes
2
answers
3k
views
Function to iterate over array
I am using the following script, so as to call a function that is supposed to iterate over an array.
#!/bin/bash
function iterarr {
for item in "$1"
do
echo "$item"
done
}
myarr=...
1
vote
1
answer
739
views
How to split Bash array into arguments
I wrote a bash script for listing python processes, ram usage and PID and status in human readable form with colored lines. But I have some trouble with working time of the script. Because of the ...
0
votes
1
answer
109
views
display array in a function - not working
What am I missing here?
I have created a simple array:
declare -a appArray=(
"item1 -a -b"
"item2 -c -d"
)
If I echo this I can see it all
echo ${appArray[@]}
> item1 -a -b item2 -c ...