All Questions
21 questions
2
votes
2
answers
603
views
For loop through a variable vector
I have a for loop and case statements. The for loop has quite a bit element list and the case statement will assign an 1D array or a vector. These values will be used in for loop after. I have the ...
0
votes
2
answers
126
views
Loop over space delimited PIDs, get number of open file handles
How may I loop over a set of PIDs delimited by spaces? I think I remember the first step is like making each element its own row?
For my Firefox sessions they are quite a few PIDs:
$ pidof firefox
...
0
votes
2
answers
996
views
For-loop - appending to arrays with iterator in the array name
I have the following problem. I have an array arr with some values. I want to sort each value into a set of different - and already declared - arrays earr$j, i.e. arr[0] into earr1, arr[1] into earr2 ...
2
votes
0
answers
289
views
for loop and appending over list of arrays
I am new to Bash scripting and presently find myself dealing with a small problem in working with for loops, arrays and variable assignment/substitution which I do not know how to solve. Since I am ...
0
votes
2
answers
2k
views
Shell script with a for loop and an “array”
How can I use this shell script with for loop and an array.
I would like to call create condition for quality gate creation of sonarqube with a for loop. Example:
#!/bin/bash --login
echo "...
1
vote
1
answer
142
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 [ ...
0
votes
1
answer
186
views
Bash array arent adding elements to last
root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# array=()
root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# for i in 1 2 3 4
> do
> array+=($i)
> done
root@kali-linux:~/Softwares/...
0
votes
0
answers
322
views
bash: problem with looping through array of directory paths
Array arr1 contains two directory paths extracted with find command:
echo "${arr1[@]}"
/archive/logs/2020/02
/archive/raw/2020/02
I am testing if I can loop through the array arr1 with this code:
...
0
votes
3
answers
402
views
Mathematical operations - Bash script
I am trying to write a script(script1.sh) that gives the sum of each digits in the first number, raised to the power of second number. So
./script1.sh 12345 2
should output 55
(because 1+4+9+16+...
0
votes
1
answer
242
views
List with two values in every List Item
I want to store a list with name and email address and use it in the single for loop. And I want to do it in Shell.
Knowing that shell list has a white space separator
list = "john, [email protected]" "...
1
vote
1
answer
855
views
Reading multiple files and operating on stored Arrays
I have 2 text files "${LinkP}" and "${QuestionP}. I want to read these files and store each complete line in the respective array,
IFS=$'\r\n' GLOBIGNORE='*' command eval "LinkA=($(cat "${LinkP}"))"
...
0
votes
1
answer
105
views
Start range from 1 onward
I am counting multiple log files with the range starting from 1 onward however it's starting from 0.
path=(/home/folder/text/*)
for 1 int ${!path}; do
printf "$s: $s\n" $i "${list[i]##*/}"...
0
votes
2
answers
222
views
Unix Script, problem with a 2d array
I have 2 arrays that refer to files for example
alpha=file 1
beta=file2
Charlie=file3
delta=file4
beta2=file5
beta3=file6
Charlie2=file7
charlie3=file8
delta2=file9
delta3=file10
array1=("$alpha" "$...
1
vote
2
answers
1k
views
Using awk to process multiple files need to count occurance of variable after pattern. How can I stop array resetting after each file?
I want to count all occurances of any variable in parenthesis after patterns, for files in a directory that have a specific extension. Each file may contain the pattern on multiple records/line.
So ...
2
votes
3
answers
777
views
list oldest file in directories in a loop
I have a set of files in a structure like so;
regions
├── ap-northeast-1
│ └── sg-66497903
│ ├── sg-66497903-2017-10-03-Tue-12.39.json
│ ├── sg-66497903-2017-10-03-Tue-12.42.json
│ ...