Skip to main content
deleted 12 characters in body
Source Link
Kalib Zen
  • 197
  • 2
  • 12

Create a dynamic string variable from a configuration text file in bash script

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.conf dynamicallytxt.

  So the content of the excluded_ext.conftxt is:

log txt png 

so whenever I add another extension in excluded_ext.conftxt, I will get an updated extension inside the variable EXCLUDE_EXTENSION. Example if I add an extra extension of 'log' inside excluded_ext.conftxt

log txt png log 

then the value of variable $EXCLUDE_EXTENSIONEXCLUDE_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.conf`txt` # create array from the text file # Im not sure how to go next. 

Create a dynamic variable from a configuration text file in bash script

I want to create a dynamic variable that holds file extension like this. The bad thing is that the 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.conf dynamically.

  the content of the excluded_ext.conf is:

log txt png 

so whenever I add another extension in excluded_ext.conf, I will get an updated extension inside the variable EXCLUDE_EXTENSION. Example if I add an extra extension of 'log' inside excluded_ext.conf

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.conf` # create array from the text file # Im not sure how to go next. 

Create a dynamic string variable from a configuration text file in bash script

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. 
Source Link
Kalib Zen
  • 197
  • 2
  • 12

Create a dynamic variable from a configuration text file in bash script

I want to create a dynamic variable that holds file extension like this. The bad thing is that the 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.conf dynamically.

the content of the excluded_ext.conf is:

log txt png 

so whenever I add another extension in excluded_ext.conf, I will get an updated extension inside the variable EXCLUDE_EXTENSION. Example if I add an extra extension of 'log' inside excluded_ext.conf

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.conf` # create array from the text file # Im not sure how to go next.