Help with the modifying apects of .bash_profile
I'm new to Linux and I'm trying to learn about .bash_profile. I want to be able to set up various aspects of it, such as setting default permissions for new files, changing the format of the prompt. I also want to modify it so that the current directory is appended to the default PATH.
Can anybody give me a brief rundown on the code/syntax and whatnot for these things? ex: what is the line that I would need to type so that my prompt is formatted "command number - user - machine name - current directory"? |
The best place to start is with the bash documentation --> https://www.gnu.org/software/bash/ma...l#SEC_Contents Section 6.2 discusses the startup files.
Here is a good place to start looking into the bash prompt --> http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/ |
How do I get changes made via the terminal to be saved? Apparently, I'm supposed to type "source ~/.bash_profile" or ". ~/.bash_profile" but it doesn't seem to be working.
For example, I typed in PS1="#\! \u@\h in \w > " to modify the prompt, and it worked. I then typed source ~/.bash_profile to save the changes, but when I re-opened the terminal it was back to the default. Is there something I'm doing wrong? Is there a way to make the changes by editing the .bash_profile in a text editor? |
Quote:
then this would ouput hello Code:
source file To modify the file, try typing in terminal: Code:
gedit ~/.bash_profile Code:
PS1="#\! \u@\h in \w > " |
So I opened up .bash_profile with the gedit command, typed the prompt code in, save it, and restarted the terminal. It still shows only the default prompt (bash-4.1$)
Here's my .bash_profile so far: Code:
# Get the aliases and functions from local config file: |
Hmm..
You know, I'm not sure if the .bash_profile file is loaded when a terminal is opened. Put this somewhere in your ~/.bashrc (which I know loads) Code:
if [ -f ~/.bash_profile ]; then source ~/.bash_profile; fi According to man page of bash, when bash is loaded on a non-login screen (opening a terminal while logged in for example) it does not read from ~/.bash_profile Quote:
Quote:
|
I put that code in the .bashrc, saved, logged out, logged back in, and opened the terminal. Here's what it says:
Code:
bash: [-f: command not found in case it helps, here's my current .bashrc (which was given to me to begin with) Code:
if [ -f ~/.bash_profile ]; then source ~/.bash_profile; fi |
Code:
[-f: command not found Code:
if [ -f ~/.bash_profile ]; then source ~/.bash_profile; fi Code:
if [-f ~/.bash_profile ]; then source ~/.bash_profile; fi |
I fixed it, but now the terminal just opens with only the cursor, no prompt. When I enter a command (like cd) it crashes.
|
Quote:
Like this: Code:
export PS1="#\! \u@\h in \w > " |
Quote:
Instead bash loads /etc/profile then only .bash_profile ( if not then .bash_login or .profile ). |
exporting the PS1 variable did not work, but I tried putting PS1="#\! \u@\h in \w > " in .bashrc and it worked. Any reason why this is the case?
edit: I also found that if I put PS1="#\! \u@\h in \w > " in .bash_profile instead of .bashrc and open the terminal the prompt is still the default. But when I type in source .bash_profile the prompt changes. |
If you can put whole of /etc/profile and /etc/profile.d/files and /home/you/.bash_profile and /home/you/.bashrc plus .profile or .bash_login then it may be possible to figure out.
|
My current .bash_profile is
Code:
# Get the aliases and functions from local config file: Code:
# Set alias(es) here: |
When launching a Bash interactive shell, it can be a login shell or a non-login shell. When launching a login shell, Bash reads /etc/profile and then the configuration files in the following order: ~/.bash_profile, ~/.bash_login, and ~/.profile. Bash executes the commands in the first of these files that it can found and read. When launching a non-login shell, it looks for ~/.bashrc.
Sourcing ~/.bashrc from ~/.bash_profile and then sourcing ~/.bash_profile from ~/.bashrc is a loop and is likely why Bash crashed when you did that. Typically, the only thing in ~/.bash_profile is Code:
if [ -f ~/.bashrc ]; then If you put your PS1 variable in ~/.bashrc, you will get the prompt you want whether using a login or non-login shell (assuming you source ~/.bashrc from ~/.bash_profile). All the other stuff you have in ~/.bash_login you should move to ~/.bashrc for the same reason. To append a directory named 'bin' that is in your home directory to your PATH, put this in ~/.bashrc Code:
export PATH=$PATH:~/bin Code:
export PATH=$PATH:$HOME/bin |
All times are GMT -5. The time now is 02:39 PM. |