bash script 질문 드립니다.

darklady78의 이미지

안녕하세요.
리눅스 초보 유저입니다.
shell scipt 처음 쓰는 유저입니다.
tcsh shell 이용해서 script를 만들어져 있던 것을
제 환경 bash shell로 바꿔서
tcsh --> bash 변경하였습니다.
이것을 ./script.sh 실행하였더니,

./script.sh: line 3: syntax error near unexpected token '('
./script.sh: line 3: 'set a = ()'

이런 메세지가 떳습니다.

이것을 해결하려면 어떻게 해야되는 건가요?

스크립트는 아래와 같습니다.

############################
#!/bin/bash -f
set file = run1.root
set a = ()
foreach x (.run_*.root)
set a = ($a $x)
end
hadd $file $a
#############################

eseo의 이미지

tcsh이 있다면, 맨 첫 라인을 tcsh로 바꿔주는 것이 가장 빠른 길일 것 같네요.

#!/bin/tcsh -f
### remove ### !/bin/bash -f
set file = run1.root
set a = ()
foreach x (.run_*.root)
set a = ($a $x)
end
hadd $file $a

---
배려하는 마음을 갖자.

doodoo의 이미지

#!/bin/bash
 
file=run1.root
a=""
 
for x in `.run_*.root`; do
    a=`$a $x`
    hadd $file $a
done

죄송합니다. 테스트는 못해봤습니다.