이 루프의 마지막 반복을 에코/인쇄하는 방법

이 루프의 마지막 반복을 에코/인쇄하는 방법
#!/bin/bash

cat /usr/local/nagios/libexec/std_filesystem.txt | while read line
do

if [ -d $line ]; then
    file_system_name="-p $line"
new_file+=" $file_system_name"
check_filesystem="$new_file"
fi
done
echo $new_file

std_filesystem.txt has the following content
/usr/jboss
/www
/www/archive
/www/logs/jboss
/www/logs/heapdump
/opt
/opt/splunk
/opt/splunk/logs
/opt/udeploy
/www-pri1
/tmp

나는 이 루프의 마지막 반복을 인쇄할 수 있기를 원합니다. /www /tmp /opt만 존재한다고 가정하면 에코는 "-p /www -p /tmp -p /op"가 되기를 원합니다. 도와 주셔서 감사합니다

답변1

필요한 작업을 수행하려면 로 변경하면 +=됩니다 =.

찾은 모든 실제 사례에 기존 값을 추가하지 않으면씌우다매번 새로운 마지막 참값이 생기고, 루프가 끝나면 마지막 참값이 에 유일한 값이 됩니다 $new_file.

관련 정보