혼자 crudini 작성하는데 if 문을 쓰면 자꾸 엉뚱한 부분을 읽어드립니다
각각의 if 문만 따로 실행하면 문제없는데 같이 하면 꼬이네요
#!/bin/csh -f
# crudini뚮뱾湲?
# 2015.9.13
#
# argv[1] = ?묒뾽?댁슜
# argv[2] = ?뚯씪?대쫫
# argv[3] = section
# argv[4] = parameter
# argv[5] = value
#
#########################
set count = 1
set line_num = `cat $argv[2] | wc -l`
set set_need = 1
set section = "="
set parameter = "="
set value = "="
echo 5set
echo $argv[1] : $#argv
if($argv[1] == --set && $#argv == 5)then
echo 5555set
while ($count <= $line_num)
set line = "`head -n $count $argv[2] | tail -n 1`"
# section parameter 媛????
set search1 = "`echo '$line' | fgrep [`"
set search2 = "`echo '$line' |fgrep =`"
echo "================================"
echo $search2
if($#search1 > 0)then # [媛 ?섏삤??뱀뀡?????
set section = "$line"
else if($#search2 > 0)then # = ???섏삤??뚮씪誘명꽣?????
set parameter = "`echo '$line' | cut -d '=' -f 1 `"
else
set parameter = ""
if($set_need == 1 && "$section" == "[$argv[3]]")then #鍮덈Ц?먯뿴?먯꽌 ?뱀뀡??媛숆퀬 ?꾩쭅 ?쎌엯???덊뻽?꾨븣
echo "$argv[4] = $argv[5]" >> data
set set_need = 0
endif
endif
echo "$section""$parameter"
# section 怨?parameter 媛믪씠 ?쇱튂?섎㈃ ?쎌엯
# ?꾨땲?洹몃깷 異쒕젰
if("$section" == "[$argv[3]]" && $parameter == "$argv[4]")then
echo "$argv[4] = $argv[5]" >> data
echo new2 : $argv[4] = $argv[5]
set set_need = 0
else
echo "$line" >> data
endif
@ count += 1
echo --------------------while_end----------------------
end
# 덉?됯퉴 媛숈? ?뱀뀡???놁쓣 寃?
if($set_need == 1)then
echo "" >> data
echo "" >> data
echo "[$argv[3]]" >> data
echo "$argv[4] = $argv[5]" >> data
endif
cat data > $argv[2]
rm -f data
endif
echo 4set
if($argv[1] == --set && $#argv == 4)then
echo 4444set
while ($count <= $line_num)
set line = "`head -n $count $argv[2] | tail -n 1`"
# section parameter 媛????
set search1 = "`echo '$line' | fgrep [`"
set search2 = "`echo '$line' |fgrep =`"
echo "================================2"
echo $search2
if($#search1 > 0)then
set section = "$line"
else if($#search2 > 0)then
set parameter = "`echo '$line' | cut -d '=' -f 1 `"
else
set parameter = ""
if($set_need == 1 && "$section" == "[$argv[3]]")then
echo "$argv[4] = " >> data
set set_need = 0
endif
endif
#section 怨?parameter 媛믪씠 ?쇱튂?섎㈃ ?쎌엯
if("$section" == "[$argv[3]]" && $parameter == "$argv[4]")then
echo "$argv[4] = " >> data
set set_need = 0
else
echo "$line" >> data
endif
@ count += 1
end
if($set_need == 1)then
echo "" >> data
echo "" >> data
echo "[$argv[3]]" >> data
echo "$argv[4] = " >> data
endif
cat data > $argv[2]
rm -f data
endif