I want to create a dynamic string variable that holds file extension from a configuration text file like this. The bad thing is that the string value contains regex expression:
EXCLUDE_EXTENSION="\.(log|txt|png)$"
where the log, txt and png extensions I get it from a text file called excluded_ext.txt. So the content of the excluded_ext.txt is:
log txt png
so whenever I add another extension in excluded_ext.txt, I will get an updated extension inside the variable EXCLUDE_EXTENSION. Example if I add an extra extension of 'log' inside excluded_ext.txt
log txt png log
then the value of variable EXCLUDE_EXTENSION should be updated automatically to:
EXCLUDE_EXTENSION="\.(log|txt|png|log)$"
I think I might need to use regex but I'm not sure how to achieve this.
#!/bin/sh # read from a text file EXCLUDED_TEXT=`cat excluded_ext.txt` # create array from the text file # Im not sure how to go next.