shell script string concatenation : not found error

Viewed 13

code

I am a very newbie about shell scripts.

I would like to read the words one line at a time from stopwords.txt and concatenate them as follows. (w1|w2|w3|w4) However, for some reason, I get a not found error. It would be helpful if you could tell me why.

test =  """#!/bin/sh
str='\\b('

cat stopwords.txt | while read line
do 
 str+='${line}|'
done
 str+='\\b)'
 echo $str
"""
with(open('test.sh', 'w')) as f:
  f.write(test)

!sh test.sh

I am running this code in Google colab.

0 Answers
Related