나는이 개 파일이 이 :bash는 스크립트 간단한 배열
john smith
adam moore
max caviar
내가 한 이미 한 것을 : 좀 봐 alik을했습니다
first=()
getfirst() {
i=0
while read line # Read a line
do
array[i]=$line # Put it into the array
i=$(($i + 1))
done < $1
}
getfirst "/tmp/first.txt"
for a in "${array[@]}"
do
echo "$a"
done
last=()
getlast() {
i=0
while read line # Read a line
do
array[i]=$line # Put it into the array
i=$(($i + 1))
done < $1
}
getlast "/tmp/first.txt"
for b in "${array[@]}"
do
echo "$b"
done
전자 (사용하여 반복) :
for x in {1..2}
do
echo $a[$x] $b[$x];
done
하지만 출력은 다음과 같습니다 당신이 paste
이없는 경우,
$ paste -d ' ' first.txt last.txt
john smith
adam moore
max caviar
사용 :
max caviar
'first'와'last' 배열을 만들지 만 절대로 사용하지 마십시오. 그런 다음 배열'a'와'b'에 접근합니다. 그러나 이것들은 배열로 선언되지 않았고 두 개의 for 루프에있는 반복 변수 일뿐입니다. – Barmar