LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-28-2012, 10:34 PM   #1
cravengemetzel
LQ Newbie
 
Registered: Dec 2012
Location: Ontario, Canada
Distribution: Netrunner Rolling
Posts: 16

Rep: Reputation: Disabled
I added a PATH to /etc/profile but "echo $PATH" says it's not there?


I added /usr/games/bin to root's PATH in the /etc/profile file, but it isn't showing up when I run "echo $PATH". I can do PATH=$PATH:/usr/games/bin but this change isn't persistent. It'll undo itself when I open a new terminal.. How do I fix this? Here is my /etc/profile configuration....

Code:
# /etc/profile: login shell setup
#
# That this file is used by any Bourne-shell derivative to setup the
# environment for login shells.
#

# Load environment settings from profile.env, which is created by
# env-update from the files in /etc/env.d
if [ -e /etc/profile.env ] ; then
	. /etc/profile.env
fi

# You should override these in your ~/.bashrc (or equivalent) for per-user
# settings.  For system defaults, you can add a new file in /etc/profile.d/.
export EDITOR=${EDITOR:-/bin/nano}
export PAGER=${PAGER:-/usr/bin/less}

# 077 would be more secure, but 022 is generally quite realistic
umask 022

# Set up PATH depending on whether we're root or a normal user.
# There's no real reason to exclude sbin paths from the normal user,
# but it can make tab-completion easier when they aren't in the
# user's PATH to pollute the executable namespace.
#
# It is intentional in the following line to use || instead of -o.
# This way the evaluation can be short-circuited and calling whoami is
# avoided.
if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
	PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games/bin:${ROOTPATH}"
else
	PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
fi
export PATH
unset ROOTPATH

if [ -n "${BASH_VERSION}" ] ; then
	# Newer bash ebuilds include /etc/bash/bashrc which will setup PS1
	# including color.  We leave out color here because not all
	# terminals support it.
	if [ -f /etc/bash/bashrc ] ; then
		# Bash login shells run only /etc/profile
		# Bash non-login shells run only /etc/bash/bashrc
		# Since we want to run /etc/bash/bashrc regardless, we source it 
		# from here.  It is unfortunate that there is no way to do 
		# this *after* the user's .bash_profile runs (without putting 
		# it in the user's dot-files), but it shouldn't make any 
		# difference.
		. /etc/bash/bashrc
	else
		PS1='\u@\h \w \$ '
	fi
else
	# Setup a bland default prompt.  Since this prompt should be useable
	# on color and non-color terminals, as well as shells that don't
	# understand sequences such as \h, don't put anything special in it.
	PS1="${USER:-$(whoami 2>/dev/null)}@$(uname -n 2>/dev/null) \$ "
fi

for sh in /etc/profile.d/*.sh ; do
	[ -r "$sh" ] && . "$sh"
done
unset sh
If I do "source /etc/profile" all the paths highlited in the /etc/profile (including regular-user paths) are added to root's PATH, but again, as soon as I exit root and become root again, this change is gone.

Last edited by cravengemetzel; 12-28-2012 at 10:39 PM.
 
Old 12-28-2012, 10:46 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,239

Rep: Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522
remove this "${ROOTPATH}" and change it to

The $PATH should not be needed for this one ?? it might depending on other files like bash.bashrc
Code:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games/bin:$PATH"
Then reboot

Last edited by John VV; 12-28-2012 at 10:54 PM.
 
Old 12-28-2012, 10:58 PM   #3
cravengemetzel
LQ Newbie
 
Registered: Dec 2012
Location: Ontario, Canada
Distribution: Netrunner Rolling
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by John VV View Post
remove this "${ROOTPATH}" and change it to

The $PATH should not be needed for this one ?? it might depending on other files like bash.bashrc
Code:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games/bin:$PATH"
Then reboot
I didn't add "${ROOTPATH}" as it was already there, all I did is squeeze /usr/games/bin before it. I am thus reluctant to remove this in case of breakage? I have no .bashrc in my home directory, nor in my root directory. The only bashrc file is in /etc/bash/bashrc and this one does not have any PATH variables in it. Here:

Code:
# /etc/bash/bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output.  So make sure this doesn't display
# anything or bad things will happen !


# Test for an interactive shell.  There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]] ; then
	# Shell is non-interactive.  Be done now!
	return
fi

# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control.  #65623
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize

# Enable history appending instead of overwriting.  #139609
shopt -s histappend

# Change the window title of X terminals 
case ${TERM} in
	xterm*|rxvt*|Eterm|aterm|kterm|gnome*|interix)
		PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
		;;
	screen)
		PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"'
		;;
esac

use_color=false

# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS.  Try to use the external file
# first to take advantage of user additions.  Use internal bash
# globbing instead of external grep binary.
safe_term=${TERM//[^[:alnum:]]/?}   # sanitize TERM
match_lhs=""
[[ -f ~/.dir_colors   ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
[[ -z ${match_lhs}    ]] \
	&& type -P dircolors >/dev/null \
	&& match_lhs=$(dircolors --print-database)
[[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true

if ${use_color} ; then
	# Enable colors for ls, etc.  Prefer ~/.dir_colors #64489
	if type -P dircolors >/dev/null ; then
		if [[ -f ~/.dir_colors ]] ; then
			eval $(dircolors -b ~/.dir_colors)
		elif [[ -f /etc/DIR_COLORS ]] ; then
			eval $(dircolors -b /etc/DIR_COLORS)
		fi
	fi

	if [[ ${EUID} == 0 ]] ; then
		PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
	else
		PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
	fi

	alias ls='ls --color=auto'
	alias grep='grep --colour=auto'
	alias egrep='egrep --colour=auto'
	alias fgrep='fgrep --colour=auto'
else
	if [[ ${EUID} == 0 ]] ; then
		# show root@ when we don't have colors
		PS1='\u@\h \W \$ '
	else
		PS1='\u@\h \w \$ '
	fi
fi

# Try to keep environment pollution down, EPA loves us.
unset use_color safe_term match_lhs
 
Old 12-28-2012, 11:19 PM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,239

Rep: Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522Reputation: 2522
then add it to the one below
and log in as a normal user
( mind you my experience is with rhel and that family of OS's )
 
Old 12-28-2012, 11:37 PM   #5
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,898

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
Copy /etc/bash/bashrc into your user and root folders as .bashrc. It serves as a template that you can edit to suit the your preferences when working as user or as root. There is no need to remove any changes you have made to /etc/bash/bashrc. The next time you have an update to bash, /etc/bash/bashrc will be overwritten. The .bashrc in you home or root folder will not be touched by an upgrade.

To make your desired PATH permanent, add this to your .bashrc:

export PATH=$PATH:/usr/games/bin

If you want to add another folder to the PATH, just add a colon and the next folder in the PATH.

Once you are done editing .bashrc, save it then run source .bashrc to immediately see the change.
 
Old 12-29-2012, 08:11 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 12,899
Blog Entries: 27

Rep: Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186
Member Response

Hi,

I agree with bigrigdriver's suggestion and I advise users to setup '.bashrc & .bash_profile for their users. Look at this LQ post #5 which shows you how to use '.bashrc' and '.bash_profile for your user. In my example you source '~/.bashrc' via '~/.bash_profile'. Modify the sample '.bashrc' to suit your needs.

HTH!
 
Old 12-30-2012, 07:52 PM   #7
cravengemetzel
LQ Newbie
 
Registered: Dec 2012
Location: Ontario, Canada
Distribution: Netrunner Rolling
Posts: 16

Original Poster
Rep: Reputation: Disabled
I dug into the Gentoo docs and came to a few realizations: $PATH variables are not typically stored in /etc/profile, but rather specified in files in the /etc/env.d directory which is then parsed with env-update and catenated into /etc/profile.env. Second, my specific problem, and the reason I was trying to edit the paths in the first place, was solved when I added myself to a group. (Stupid me! This should have been the first thing that I checked..)

And finally, there is a small discrepancy in that the $ROOTPATH in a no-x environment differs from the $ROOTPATH in my X environment (the one in the no-x environment holds more directories than the one in the X environment). But this is a really, really, really small problem as root is authorized to do anything, anyway - so now I'm marking this thread as solved. Thanks for all your help, I really do appreciate it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] "Command not found" for all but pwd and echo, PATH is empty ManiacBlaster Linux - Newbie 5 03-01-2011 12:45 PM
can I get the absolute path without giving a "path" but a inode number by C? twwwater Programming 7 08-15-2010 09:16 PM
Cedega and Fat32 (Invalid path "." given for "--use-dos-cwd") bdox Linux - Games 0 03-26-2005 03:48 AM
"echo $path" acj Linux - Newbie 8 02-04-2005 06:56 PM
want full description of "echo num > / path/...." zameer_india Linux - Newbie 5 01-08-2005 04:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration