how can I read a text file and save it to a variable in bash ? my code is here :
#!/bin/bash
TEXT="dummy"
echo "Please, enter your project name"
read PROJECT_NAME
mkdir $PROJECT_NAME
cp -r -f /home/reza/Templates/Template\ Project/* $PROJECT_NAME
cd $PROJECT_NAME/Latest
TEXT = `cat configure.ac ` ## problem is here !!!
CHANGED_TEXT=${TEXT//ProjectName/$PROJECT_NAME}
echo $CHANGED_TEXT
The issue is that you have an extra space. Assignment requires zero spaces between the =
operator. However, with bash
you can use:
TEXT=$(<configure.ac)
You'll also want to make sure you quote your variables to preserve newlines
CHANGED_TEXT="${TEXT//ProjectName/$PROJECT_NAME}"
echo "$CHANGED_TEXT"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With