Tuesday, May 7, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 11081  / 3 Years ago, tue, july 6, 2021, 3:11:26
#!/bin/bash
cd /pg
file=`ls -l |awk '{print $9}'`
list=()
for i in $a
do
echo $i
a=`cat /pg/$i | head -n 1 |awk '{print $8}' ` #output: first interation 15 & 2nd values 60
list+=($a)

#a1=`cat /pg/$i | head -n 2 |awk '{print $8}'`
done
echo $list

through this a=`ls -l |awk '{print $9}'` I'm getting two file and iterating through for loop
and appending values to list() the list should contains "15","16" but list contains only one value is "15"
Please help me to fix the same.


More From » bash

 Answers
5

To access the whole array, use


echo "${list[@]}"

Using just $list is equivalent to ${list[0]}, i.e. it only shows the first element.


[#1202] Thursday, July 8, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iedncommon

Total Points: 200
Total Questions: 95
Total Answers: 132

Location: Tonga
Member since Mon, Aug 2, 2021
3 Years ago
iedncommon questions
;