LinuxQuestions.org
Review your favorite Linux distribution.
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 05-07-2015, 07:43 PM   #1
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 450

Rep: Reputation: 29
.profile and bash.rc


hi guys

i was taught that /etc/profile was global for environmental variables and settings...and ~/.profile was specific to the user...

and that bash.rc and ~/.bash.rc was for aliases and functions...i was trying to setup a permanent alias in my profile to a common ssh command and read that it should be going into .profile??? is it really not strict or just a rule of thumb?
 
Old 05-08-2015, 04:30 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Historically and standards-wise local additions should go to /usr/local and personal changes to ~/. The reason for that is that when upgrading a whole system these changes don't get undone, reverted or otherwise lost. Given that functions, aliases and commands that are used system-wide could be in /etc/profile.d/* but personal ones should be in ~/.bash_profile or ~/.bashrc. As far as "strictness" is concerned it depends how you look at it: casual users may think of it as "no fun" but others really don't want each system they need to work on to show a difference in behaviour that might potentially bite them...
 
Old 05-08-2015, 05:04 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,110

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
I would suggest you to read man bash especially the section about login (look for invocation)
 
Old 05-08-2015, 07:25 AM   #4
P4z
LQ Newbie
 
Registered: Apr 2015
Location: Silesia
Distribution: Debian Stretch
Posts: 5

Rep: Reputation: 0
EDIT-DELETE: posted similar content in the next post after not finding this original one. sorry for confusion. hope to never see it again by me :P

Last edited by P4z; 05-15-2015 at 06:13 AM. Reason: accidentally double posted
 
Old 05-08-2015, 07:31 AM   #5
P4z
LQ Newbie
 
Registered: Apr 2015
Location: Silesia
Distribution: Debian Stretch
Posts: 5

Rep: Reputation: 0
sigint-ninja, keep in mind that other shells e.g. tcsh incorporate different syntax than bash therefore be careful about your general profile scripts and use conditions when required

for ssh customs you may be also interested in the Host directive of ssh_config

personally I create custom commands in /usr/local/bin more frequently than shell aliases because they are much more flexible

good luck!
 
Old 05-08-2015, 09:52 AM   #6
sudowtf
Member
 
Registered: Nov 2013
Posts: 187

Rep: Reputation: 45
I don't know the "standard" but for my ~/ somewhere in time i came across this and therefore you can proceed as your O.P. describes:

In ~/.profile, i have the following code near the end:
Code:
# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
	. "$HOME/.bashrc"
    fi
fi
which implies it only loads for bash. You could remove the outer if-statement if you use other shells.
 
Old 05-08-2015, 10:52 AM   #7
GazL
Senior Member
 
Registered: May 2008
Posts: 4,083
Blog Entries: 1

Rep: Reputation: 1527Reputation: 1527Reputation: 1527Reputation: 1527Reputation: 1527Reputation: 1527Reputation: 1527Reputation: 1527Reputation: 1527Reputation: 1527Reputation: 1527
I use this:
Code:
# /etc/profile.d/80-bashrc.sh  #########################################
#
# Run user's ~/.bashrc file if shell is bash, and interactive:
#

if [ -n "$BASH" ] && [ -z "$POSIXLY_CORRECT" ] ; then
  case $- in
  *i* )  # Interactive shell
         if [ -f ~/.bashrc ]; then
            source ~/.bashrc
         fi
         ;;
  esac
fi

########################################################################
It's not appropriate to run ~/.bashrc for non-interactive shells, shells other than bash, or for bash when running as /bin/sh (POSIXLY_CORRECT).

If you want to do it on a user by user basis rather than system wide you can put it in the users ~/.bash_profile instead of /etc/profile or a member of profile.d.
 
1 members found this post helpful.
Old 05-08-2015, 12:18 PM   #8
sudowtf
Member
 
Registered: Nov 2013
Posts: 187

Rep: Reputation: 45
Quote:
Originally Posted by GazL View Post
[...]It's not appropriate[...]
Thank you!
 
  


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
Need help about bash profile file. gardenair Linux - Newbie 6 03-05-2010 08:50 AM
Slackware bash profile ibwew Slackware 10 09-13-2009 01:36 PM
Bash Profile ...... babujd Linux - Newbie 16 07-23-2009 07:25 PM
/etc/profile vs. /etc/bash.bashrc jbrashear Debian 3 03-11-2004 04:49 PM
where is my bash profile? bandofmercy Linux - General 3 04-08-2003 06:29 PM


All times are GMT -5. The time now is 08:46 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