LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash profile setting (https://www.linuxquestions.org/questions/linux-newbie-8/bash-profile-setting-774870/)

nagavinodh 12-10-2009 11:21 PM

bash profile setting
 
hi,

i tried to set the apache home in red hat.we have two apache home one is default and another one is istalled newly.
we create the user apache.

bash_profile

echo please type the apache home
read c
a=new
if $c=$a
then
export APACHE_HOME=/usr/local/apache2
PATH=$PATH:$APACHE_HOME/bin
else
export APACHE_HOME1=/etc/httpd
fi

we got the following errors

please type the apache home
new
-bash: new=new: command not found

is it possible to set the two apache homes in same bash profile.

jhwilliams 12-10-2009 11:36 PM

This should solve your problem -- change the line
Code:

if $a=$c
to
Code:

if [ "$a" = "$c" ]

kbp 12-10-2009 11:41 PM

Tests need to be in square brackets '[]'

eg.
if [ $c = $a ]
then
# do something

fi

I usually put strings in double quotes and leave numbers bare

eg
STRING1="some garbage"
if [ "$STRING1" = "hello" ] ....

COUNT=5
if [ $COUNT -eq 7 ] ...

Please note there are different types of tests depending on the data types, here's a reference:
http://www.oreillynet.com/linux/cmd/cmd.csp?path=t/test

cheers

chrism01 12-11-2009 12:37 AM

Double brackets [[ ]] is more robust http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS

catkin 12-11-2009 12:44 AM

What kpb wrote except [[ ]] is preferred for testing over [ ].


All times are GMT -5. The time now is 12:04 AM.