Where is .bash_profile file or his equivalent?

If none of the more specific forums is the right place to ask

Where is .bash_profile file or his equivalent?

Postby mono » 2009-05-22 18:57

Hi, I want to ask you where is .bash_profile file or his equivalent? I want to change variable PATH. In Fedora distro was in home directoty file .bash_profile in which was variable PATH. I could change PATH in this file... But in Debian I cant find this file. Can you advise me where change PATH? Thanks
mono
 
Posts: 142
Joined: 2009-05-10 14:39

Re: Where is .bash_profile file or his equivalent?

Postby Telemachus » 2009-05-22 19:02

If you do ls -A, you should have both a .bashrc and a .profile. You probably want to edit .bashrc instead. Both .profile and .bash_profile are for login shells, and depending on what you do, many of your shells (in an X environment) will be non-login shells. The good news is that by default Debian's .profile automatically sources .bashrc, so anything you put in .bashrc gets sourced either way.
"We have not been faced with the need to satisfy someone else's requirements, and for this freedom we are grateful."
Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System
User avatar
Telemachus
 
Posts: 4676
Joined: 2006-12-25 15:53

Re: Where is .bash_profile file or his equivalent?

Postby smallchange » 2009-05-22 19:29

To explain why you might like to know that bash will source .profile if .bash_profile does not exist, and other shells will source .profile, while only bash will us .bash_profile, so using .profile allows configuration for other shells to be set as well.
smallchange
 
Posts: 1740
Joined: 2009-05-04 15:56

Re: Where is .bash_profile file or his equivalent?

Postby mono » 2009-05-22 20:08

I use Bash... I looked to .profile and I found there the following line PATH="$HOME/bin:$PATH". Do I understand correct that in variable PATH is saved path to the home directory and bin directory? I dont understand what does mean $PATH on the end of this line.
mono
 
Posts: 142
Joined: 2009-05-10 14:39

Re: Where is .bash_profile file or his equivalent?

Postby didi » 2009-05-22 22:05

mono wrote:I use Bash... I looked to .profile and I found there the following line PATH="$HOME/bin:$PATH". Do I understand correct that in variable PATH is saved path to the home directory and bin directory? I dont understand what does mean $PATH on the end of this line.

A colon (:) is the separator character in *nix, so what that statement does is add $HOME/bin to the existing value of $PATH.
In other words: the new PATH is $HOME/bin + the old PATH
Testing (server) + Unstable (workstation) 32-bit on AMD Athlon64 X2
didi
 
Posts: 909
Joined: 2007-12-04 16:26
Location: the Netherlands

Re: Where is .bash_profile file or his equivalent?

Postby mono » 2009-05-23 08:12

Ok but when I added new directory(sbin) into PATH: PATH="$HOME/bin:/sbin:$PATH" and then I figured variable PATH so I got the following statement bash: /usr/local/bin:/usr/bin:/bin:/usr/games:. sbin is not in PATH. How can I add new directoty into PATH?
mono
 
Posts: 142
Joined: 2009-05-10 14:39

Re: Where is .bash_profile file or his equivalent?

Postby Telemachus » 2009-05-23 09:45

mono wrote:Ok but when I added new directory(sbin) into PATH: PATH="$HOME/bin:/sbin:$PATH" and then I figured variable PATH so I got the following statement bash: /usr/local/bin:/usr/bin:/bin:/usr/games:. sbin is not in PATH. How can I add new directoty into PATH?

After you add the new directory, you have to either log out and log back in or re-source whatever file you edited. So, let's assume you are editing the $PATH in .profile. After you finish your editing, do this:
Code: Select all
. .profile

The command . sources the .profile file again. After that, you should see the updated $PATH variable.
"We have not been faced with the need to satisfy someone else's requirements, and for this freedom we are grateful."
Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System
User avatar
Telemachus
 
Posts: 4676
Joined: 2006-12-25 15:53

Re: Where is .bash_profile file or his equivalent?

Postby mono » 2009-05-23 16:25

I did like you said, but my $PATH looks still same. I wrote to .profile PATH="$HOME/bin:/sbin:/bin:/home" but when I display variable PATH so I see the following: bash: /usr/local/bin:/usr/bin:/bin:/usr/games:
mono
 
Posts: 142
Joined: 2009-05-10 14:39

Re: Where is .bash_profile file or his equivalent?

Postby smallchange » 2009-05-23 21:42

I think you are missing the export statement.
Code: Select all
export PATH=$PATH:/sbin
should give you what you want. Your $HOME/bin will be added by .bashrc if you have not changed that file and if $HOME/bin exists. It will also be added at the end of your path which is almost always better.
smallchange
 
Posts: 1740
Joined: 2009-05-04 15:56

Re: Where is .bash_profile file or his equivalent?

Postby Telemachus » 2009-05-23 22:19

smallchange wrote:I think you are missing the export statement.
Code: Select all
export PATH=$PATH:/sbin
should give you what you want. Your $HOME/bin will be added by .bashrc if you have not changed that file and if $HOME/bin exists. It will also be added at the end of your path which is almost always better.

I doubt that's the problem since export is not required in this case. All I have in my .profile is this, and it works like a charm:
Code: Select all
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi


@ Mono - Please post the output of this command:
Code: Select all
 cat .profile .bashrc
"We have not been faced with the need to satisfy someone else's requirements, and for this freedom we are grateful."
Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System
User avatar
Telemachus
 
Posts: 4676
Joined: 2006-12-25 15:53

Re: Where is .bash_profile file or his equivalent?

Postby smallchange » 2009-05-23 23:33

You are right about the export. PATH is a reserved variable in bash that is automatically exported as part of the environment.
smallchange
 
Posts: 1740
Joined: 2009-05-04 15:56

Re: Where is .bash_profile file or his equivalent?

Postby mono » 2009-05-24 06:31

Here are exports from profile and bashrc.
cat .profile .bashrc
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then

#originally
# PATH="$HOME/bin:$PATH"

#newly added
PATH="$HOME/bin:/sbin:/bin:/home"



fi
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
export HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

#if [ -f ~/.bash_aliases ]; then
# . ~/.bash_aliases
#fi

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'

#alias grep='grep --color=auto'
#alias fgrep='fgrep --color=auto'
#alias egrep='egrep --color=auto'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
polo@debian:~$ export PATH=$PATH:/sbinexport PATH=$PATH:/sbin
mono
 
Posts: 142
Joined: 2009-05-10 14:39

Re: Where is .bash_profile file or his equivalent?

Postby Telemachus » 2009-05-24 10:16

A few things:
  1. Please wrap quotations like this in code tags. It makes it much easier to read since those tags preserve indentation.
  2. You have your new $PATH setting inside an if test that may not be true. It says, "Make this my new path if I have a directory called 'bin' in my home directory." Do you have such a directory? (You can check with ls if you're not sure. An answer to this problem is to move your new $PATH setting below the if...fi structure:
    Code: Select all
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
        #originally
        # PATH="$HOME/bin:$PATH"

        #newly added
        ## REMOVE THIS -- PATH="$HOME/bin:/sbin:/bin:/home"
    fi
    # Put the $PATH below here
    PATH="$HOME/bin:/sbin:/bin:/home"

  3. Finally, the path you are trying to set is very odd. You aren't giving yourself access to /usr/bin or /usr/local, both of which are pretty normal places to find software. (I have around 1800 executables in /usr/bin as an example.) On the other hand, do you really expect to install software in /home?
"We have not been faced with the need to satisfy someone else's requirements, and for this freedom we are grateful."
Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System
User avatar
Telemachus
 
Posts: 4676
Joined: 2006-12-25 15:53

Re: Where is .bash_profile file or his equivalent?

Postby mono » 2009-05-24 14:49

Code: Select all
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
#originally
# PATH="$HOME/bin:/sbin:$PATH"

fi
#newly write
PATH="$HOME/bin:/sbin:/bin:"


No, I dont expect that I will install SW from home. It was just test directory. Problem is still here. Look at my code and look what display env command:PATH=/usr/local/bin:/usr/bin:/bin:/usr/games. The PATH is still the same:(
mono
 
Posts: 142
Joined: 2009-05-10 14:39

Re: Where is .bash_profile file or his equivalent?

Postby Telemachus » 2009-05-24 14:52

mono wrote:
Code: Select all
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
#originally
# PATH="$HOME/bin:/sbin:$PATH"

fi
#newly write
PATH="$HOME/bin:/sbin:/bin:"


No, I dont expect that I will install SW from home. It was just test directory. Problem is still here. Look at my code and look what display env command:PATH=/usr/local/bin:/usr/bin:/bin:/usr/games. The PATH is still the same:(

First, you should remove the final ':' from the $PATH setting. Second, have you logged into a new shell or resourced your .profile? Try this:

Code: Select all
source ~/.profile
echo $PATH
"We have not been faced with the need to satisfy someone else's requirements, and for this freedom we are grateful."
Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System
User avatar
Telemachus
 
Posts: 4676
Joined: 2006-12-25 15:53

Next

Return to General Questions

Who is online

Users browsing this forum: No registered users and 11 guests

fashionable