배쉬 프로그래밍 질문
글쓴이: jbssy / 작성시간: 목, 2004/01/08 - 11:46오후
euckr2utf8 dirname1 dirname2
했을 때 dirname1 디렉토리에 있는 파일의 인코딩이 모두 utf8로 바뀌어 dirname2에 저장되는 프로그램을 만들고 있습니다.
그런데 만약... dirname1에 또 다른 디렉토리가 있을 때 어떻게 처리를 해야 할지 질문을 드립니다. 재귀적 명령으로 행 중간에
$0 어쩌고 저쩌고 해봤는데도 잘 안되는 군요.. :?:
파일 소스
#!/bin/sh
if [ $# -ne 2 ]
then
echo "Please check the usage of $0 "
exit 0
fi
if [ -d "$1" ]
then
echo "Make the directory $2 to store the UTF-8 encoding files "
mkdir $2
OUTPUT_DIR=`basename $2`
else
echo "$1 is a not directory, please check the usage of $0"
exit 0
fi
for file in $1*
do
FILE_BASENAME=`basename $file`
if [ -d "$file" ]
then
CUR_DIR=`basename $file`
echo "$CUR_DIR is directory. "
echo
else
iconv -f EUC-KR -t UTF-8 $file -o $OUTPUT_DIR/$FILE_BASENAME
fi
done
exit 0
[/code]Forums:


recursive하게 가져 오실려구요?그럼 find 같은 명령으로
recursive하게 가져 오실려구요?
그럼 find 같은 명령으로 리스트를 얻어 오시는 것도 좋을 듯...
There is no spoon. Neo from the Matrix 1999.
Find를 이용해서...
source="$1" target="$2" mkdir -p $target for name in `find $source -type f -print` do iconv -f EUC-KR -t UTF-8 $name -o "$target${name#$source}" done이렇게 하면 될것 같네요.
혹시 loop 없이 find만 사용하시려면 아래와 같이 하세요.
source="$1" target="$2" mkdir -p $target find $source -type f -exec `name={}; echo "iconv -f EUC-KR -t UTF-8 $name -o $target${name#$source}"` \;[code:1]mkdir outcp -r srcdir out/fi
mkdir out cp -r srcdir out/ find .srcdir | awk '{ print "iconv -f EUC-KR -t UTF-8 " $1 " -o out/" $1 }' | sh저는 보통 이런 식으로 처리합니다. :lol:
There is no spoon. Neo from the Matrix 1999.
버스 끊길까봐 급하게 질문을 올렸었는데...집에 와보니 벌써~
버스 끊길까봐 급하게 질문을 올렸었는데...
집에 와보니 벌써~ :D
다들 감사합니다~~
LINUH DESKTOP - Never be alone again
댓글 달기