Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save a text file in a variable in bash

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
like image 650
reza Avatar asked Feb 05 '12 02:02

reza


1 Answers

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"
like image 189
SiegeX Avatar answered Oct 28 '22 08:10

SiegeX