Solved

How to source .bash_profile?

Posted on 2012-04-04
18
929 Views
Last Modified: 2013-11-13
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!
0
Comment
Question by:studious01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 4
  • +1
18 Comments
 
LVL 21

Expert Comment

by:oleggold
ID: 37808130
You don't have to actually use "source .bash_profile" but can just limit Yourself to .bash_profile
0
 
LVL 21

Expert Comment

by:oleggold
ID: 37808137
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
 
LVL 21

Expert Comment

by:oleggold
ID: 37808153
other option use "~/.bash_profile" that by default replaces "source" by going to You home directory .bash_profile ,
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 21

Expert Comment

by:oleggold
ID: 37808154
also make sure You're using right shell,eg:
!/etc/bin/sh
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 37808573
use the blow command

. ~/.bash_profile

please note the dot and space above
0
 

Author Comment

by:studious01
ID: 37808697
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 37808704
what is the content of the .bash_profile?

What is your expectation from sourcing the file?
0
 

Author Comment

by:studious01
ID: 37808764
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 37808770
what you get when you run

echo $NOW

or

set

or

env

also what are you expecting from

NOW='$date'
0
 

Author Comment

by:studious01
ID: 37808979
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
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 37809024
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
 

Author Comment

by:studious01
ID: 37809104
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
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 37809147
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
 

Author Comment

by:studious01
ID: 37809194
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
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 37809213
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
 

Assisted Solution

by:studious01
studious01 earned 0 total points
ID: 37809304
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
 
LVL 30

Accepted Solution

by:
Kerem ERSOY earned 500 total points
ID: 37810171
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
 

Author Closing Comment

by:studious01
ID: 37991637
I also did some research of my own.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question