bash - Conditional Parameter Substitution while using cat -


i'm using cat create file environment variable.

cat <<eof > config environment = ${environment:-dev} eof 

i need dev, if development or develop. cannot trim because, has other possible values qa, demo, staging etc.

please note: cannot use if statement, in environment. used in jenkins execute shell, have parameterized build, using if require me repeat above cat, multiple times

any easy way guys..

regards, shan

try this:

cat <<eof > config   environment = $([[ "${environment}" =~ ^dev ]] && environment=dev && echo $environment) eof 

Comments

Popular posts from this blog

multithreading - Exception in Application constructor -

React Native allow user to reorder elements in a scrollview list -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -