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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oleggoldCommented:
You don't have to actually use "source .bash_profile" but can just limit Yourself to .bash_profile
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.
oleggoldCommented:
other option use "~/.bash_profile" that by default replaces "source" by going to You home directory .bash_profile ,
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

oleggoldCommented:
also make sure You're using right shell,eg:
!/etc/bin/sh
omarfaridCommented:
use the blow command

. ~/.bash_profile

please note the dot and space above
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!
omarfaridCommented:
what is the content of the .bash_profile?

What is your expectation from sourcing the file?
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.
omarfaridCommented:
what you get when you run

echo $NOW

or

set

or

env

also what are you expecting from

NOW='$date'
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.
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.
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.
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.
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?
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.
studious01Author 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.
Kerem ERSOYPresidentCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
studious01Author Commented:
I also did some research of my own.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.