Bash for and while?
for
$ cat for.sh
#!/bin/bash
LISTS=("a" "b" "c")
# Don't forget Brace!
echo ${LISTS[0]}
echo ${LISTS[1]}
echo ${LISTS[2]}
# Don't forget Brace!
for item in ${LISTS[@]}
do
echo $item
done
$ ./for.sh
a
b
c
a
b
c
아래는 find, eval, sed 를 함께 쓴 예제
for file in $(find . -name "*.txt")
do
echo $file
eval sed -i "/confidential/d" $file # confidential 이 포함된 라인 지우기
done
while
필자는 while보다는 for문을 더 좋아하는 스타일이라 잘 쓰진않지만, 텍스트 파일로 부터 line 을 읽어들여 작업하는 용도로 좀 쓴다.
$ while read line; do git rm -r $line; done < remove.lst