나는 이 스크립트를 만들었습니다:
#PACKAGES.TXT
array2=(
`find . -type f -iname *t?z|awk '{print $1}'|cut -d / -f 3`
)
funzioneZ() {
echo -e " PACKAGE NAME: $i "
}
array3=(
`find . -type f -iname *t?z|awk '{print $1}'|cut -d / -f 1,2`
)
funzioneA() {
echo -e " PACKAGE LOCATION: $i "
}
array4=(
`for i in */*txz;do xz -l $i |tail -n 1|cut -d . -f 1|awk '{print $3, "K"}'; done`
)
funzioneB() {
echo -e " PACKAGE SIZE (compressed): $i "
}
rm MANIFEST2
for i in ${array2[@]};do funzioneZ $i >> MANIFEST2;done
for i in ${array3[@]};do funzioneA $i >> MANIFEST2;done
for i in ${array4[@]};do funzioneB $i >> MANIFEST2;done
실제 결과:
PACKAGE NAME: pam-1.1.8-x86_64-2mg.txz
PACKAGE NAME: tvtime-1.0.2-x86_64-3_SBo.txz
PACKAGE LOCATION: ./a
PACKAGE LOCATION: ./x
PACKAGE SIZE (compressed): 453
PACKAGE SIZE (compressed): 606
그러나 나는 결과가 다음과 같기를 원합니다.
PACKAGE NAME: pam-1.1.8-x86_64-2mg.txz
PACKAGE LOCATION: ./a
PACKAGE SIZE (compressed): 453
PACKAGE NAME: tvtime-1.0.2-x86_64-3_SBo.txz
PACKAGE LOCATION: ./x
PACKAGE SIZE (compressed): 606
어떻게 해야 하나요?
답변1
해결책 찾기: 깨끗하고 단순함
for i in ${array1[@]};do echo -e "PACKAGE NAME:$i " >> MANIFEST2 && echo -e "PACKAGE SIZE: `xz -l $i |tail -n 1|cut -d . -f 1|awk '{print $3, "K"}'`" >> PACKAGES.TXT
PACKAGE NAME:a/pam-1.1.8-x86_64-2mg.txz
PACKAGE SIZE: 453 K
PACKAGE NAME:x/tvtime-1.0.2-x86_64-3_SBo.txz
PACKAGE SIZE: 606 K