How to source .bash_profile?

Hi Experts,

I am trying to reload a environment variable that I added to my .bash_profile.  And, based upon my research I should type the command "source .bash_profile" at the $ prompt.
But, after doing so this is displayed on the next line, "=>".  Can someone tell me what is supposed typed at this point?

Thanks in advance!
studious01Asked:
Who is Participating?
 
Kerem ERSOYConnect With a Mentor PresidentCommented:
Then, use the "." builtin to put the new value assigned to the NOW variable into effect.
. ~/.bashrc

As I've indicated earlier don't forget that "." will return the current directory in absolute path format (i.e., with leading "/") so does "~".

But in the ". ./.bashrc" usage the beginning dot means that the following command should be executed in the current shell. If it was not then the .bashrc would  run in a new shell and then all the exports (NOW variable) would be lost when the shell terminates...

Yes, I did some reading form my Linux book.  But, I still don't know why it didn't work from
the .bash_profile file.

This is because .bash_profile is executed iff it is in .bashrc. If not it will not be executed. The only profile executed during logon is the default /etc/profile and .bashrc. If you had included the .bash_profile into .bashrc it would then be executed during logon.

Cheers,
K.
0
 
oleggoldCommented:
You don't have to actually use "source .bash_profile" but can just limit Yourself to .bash_profile
0
 
oleggoldCommented:
Try ".bash_profile" without anything in Your script,sometime You need to  give a space between "." and bash_profile or use absolute path ,if Your script isn't in the same directory .bash_profile is.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
oleggoldCommented:
other option use "~/.bash_profile" that by default replaces "source" by going to You home directory .bash_profile ,
0
 
oleggoldCommented:
also make sure You're using right shell,eg:
!/etc/bin/sh
0
 
omarfaridCommented:
use the blow command

. ~/.bash_profile

please note the dot and space above
0
 
studious01Author Commented:
I just tried typing in '. ~/.bash_profile and received the same results.
Also, I should mention the steps that are taken before typing the command above.
1. I sudo from the oracle user to user1
2. I cd  to the home directory for user1 where the .bash_profile file resides, which is /home/user1
3. Then I type the command above which is, '. ~/.bash_profile'

Output
-----------
localhost:user1:orcl:/home/user1
=>

Is there something that I am supposed to type next?
Lastly, I typed echo $SHELL and received back /bin/bash.

Thanks again!
0
 
omarfaridCommented:
what is the content of the .bash_profile?

What is your expectation from sourcing the file?
0
 
studious01Author Commented:
This is from the beginning of the .bash_profile:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
      . ~/.bashrc
fi

But, I just added this variable:
NOW='$date'
export NOW

And, I would like to be able to use the $NOW within the current session.
0
 
omarfaridCommented:
what you get when you run

echo $NOW

or

set

or

env

also what are you expecting from

NOW='$date'
0
 
studious01Author Commented:
If I type echo $NOW, I get a blank line.  And, if I type env that variable does not appear.
Also, I should have type it has NOW=$date.  I would like the date to be returned, but even if I type a string as 'TEST',  a blank line is still returned.
0
 
Kerem ERSOYPresidentCommented:
Hi,


You either run the command like that

. ./.bash_profile

Open in new window


please note the dot and space before ~/.bash_profile

or

source ~/.bash_profile

Open in new window


The problem with your syntax was you did not mention any path so the source command could not find your .bash_profile.

Cheers,
K.
0
 
studious01Author Commented:
KeremE- So, in both examples that you gave I must indicate the path?

So, the syntax would be:

. ./home/user1/.bash_profile

or

source ~/home/user1/.bash_profile

Because, I typed . ./home/user1/.bash_profile and received the following error message,
"bash: ./home/user1/.bash_profile: No such file or directory

And, I received the same error message for the second command as well.
0
 
Kerem ERSOYPresidentCommented:
Nope you are doing it wrong:

./home/user1/.bash_profile

means you will be looking for home/user1/.bash_profile under the current directory Probably you're under your home. It would only find the file if you are on the root "/" directory. What you'll need to type is just: ./.bash_profile if you're already on your home directory or ~/.bash_profile if you're cd'd to anywhere else.

Don't forget that "." means the current directory and it is most likely be your home (/home/user1) and  
./home/user1/.bash_profile  means /home/user1/home7user1/.bash_profile which is unlikely to be a valid directory.

Also ~/home/user1/.bash_profile does not work since "~" already a shortcut for the users home (/home/user1) so
~/home/user1/.bash_profile means /home/user1/home/user1/.bash_profile. It does not work for the same reason...

Cheers,
K.
0
 
studious01Author Commented:
okay, I typed ./.bash_profile at the home directory and then echo $NOW and the result was a blank line that followed.
Also, if I type a space after the ".", while at the home directory (. /.bash_profile), then the error message of "bash: /.bash_profile: No such file or directory" is received.

Do you have any other suggestions?
0
 
Kerem ERSOYPresidentCommented:
okay, I typed ./.bash_profile at the home directory and then echo $NOW and the result was a blank line that followed.

So if you did not modify the contents of your .bash_profile earlier. It won't be adding a variable called NOW so this normal..

Please use the "ls -al" command to see the files under your home directory.

Cheers,
K.
0
 
studious01Connect With a Mentor Author Commented:
I ultimately placed the variable in the .bashrc file and it worked fine.

code added to .bashrc file:
export NOW=$(date)

Then, use the "." builtin to put the new value assigned to the NOW variable into effect.
. ~/.bashrc

Yes, I did some reading form my Linux book.  But, I still don't know why it didn't work from
the .bash_profile file.

I appreciate all of the responses.
0
 
studious01Author Commented:
I also did some research of my own.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.