bash script

How can i conver the following to the bash shell script?

 
#! /bin/csh

set deli = '|'
set ppattern = ""
foreach i(`cat pattern`)
set ppattern = "$i$deli$ppattern"
echo $ppattern
end
foreach j (`find . -name "*.txt"`)
egrep $ppattern $j > afile
mv -f  afile $j
        rm  -f afile
end
#!/bin/bash

#set deli = '|'
deli="|"
#set ppattern = ""
#foreach i(`cat pattern`)
for i in $(<pattern)
#set ppattern = "$i$deli$ppattern"
do ppattern="$i$deli$ppattern"
echo $ppattern
#end
done

#foreach j (`find . -name "*.txt"`)
for j in *.txt
do egrep $ppattern $j > afile
   mv -f afile $j
   rm -f afile
#end
done 

seems ok, otherwise just add an -x to the shebang, and paste the output.

1 Like

Thanks, I am testing now

---------- Post updated at 09:50 PM ---------- Previous update was at 09:44 PM ----------

:q!
bash-3.00$ sh -x ttt.sh
+ deli = | 
ttt.sh: deli: not found
+ ppattern =  
ttt.sh: ppattern: not found
+ cat pattern 
+ ppattern = Wac 
ttt.sh: ppattern: not found
+ ppattern = Enpp6 
ttt.sh: ppattern: not found
+ ppattern = Nos1 
ttt.sh: ppattern: not found
+ ppattern = Glo1 
ttt.sh: ppattern: not found
+ find . -name *.txt 
+ egrep ./gg.txt

oh, no!! please, don't test a bash script calling it with

sh anyscript

it'll use sh as the interpreter
call it the proper way

./anyscript

let the shebang do its job

1 Like

Thank you,

after run ./myscript.sh

nothing happened! where to get the output?
thanks

there was a typo. I corrected it.