Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to alter system-wide $PATH for non-interactive, non-login bash shells invoked via sshd?



[When starting a non-interactive non-login shell from an ssh session...]
  What bash does is source /etc/bashrc and ~/.bashrc--it evidently
  treats ssh like rsh and does a little more than is documented even for
  rsh (search for rsh in the bash man page for details).

So another, simpler, system-wide solution is to set your $PATH in /etc/bashrc. However, this is not documented in the bash man page (which is why I came up with the more complicated solution, as I hadn't realised this behaviour at that stage). So I'm not sure whether it is standard/will occur on all systems, etc.

If you're like me and like to have interactive stuff in bashrc and login
stuff in profile, you can arrange your files like this (very similar to
before, but ~/.bashrc needn't source /etc/profile now, nor do its check
with $- and grep, as /etc/bashrc does that and avoids setting $PS1).

   In /etc/profile

     # System-wide .profile for sh(1)
     PATH=...
     export PATH
     # Source /etc/bashrc for interactive shells.
     [ -n "$PS1" -a -r /etc/bashrc ] && source /etc/bashrc
     ... stuff for login shells (more environment mostly)

   In /etc/bashrc

     # System-wide .bashrc file for interactive bash(1) shells.
     # If the shell isn't actually interactive it is an ssh session, and
     # we want to source etc/profile instead.
     if [ -z "$PS1" ] ; then
       [ -r /etc/profile ] && source /etc/profile
       return
     fi
     ... stuff for interactive shells (aliases and terminal stuff mostly)

   In ~/.profile

     # For login shells (interactive or not).
     # For interactive non-login shells see ~/.bashrc.
     # For non-interactive non-login ssh shells see ~/.bashrc.
     # For other non-interactive non-login shells see $BASH_ENV.
     # At present this is sourced by ~/.bashrc for the ssh case, so
     # all ssh sessions act like login sessions.
     PATH=...
     export PATH
     # Source ~/.bashrc for interactive shells.
     if [ -n "$PS1" -a -r ~/.bashrc ]; then source ~/.bashrc ; fi
     ... stuff for login shells (more environment mostly)

   In ~/.bashrc

     # For interactive non-login shells
     # and non-interactive non-login ssh shells.
     # For login shells (interactive or not) see first existent of
     # ~/.bash_profile, ~/.bash_login and ~/.profile.
     # For other non-interactive non-login shells see $BASH_ENV.
     # At present, this is sourced by ~/.profile so runs for all
     # interactive shells (login or not).
     # If the shell isn't actually interactive it is an ssh session, and
     # we want to source ~/.profile instead.
     if [ -z "$PS1" ] ; then
       source ~/.profile
       return
     fi
     ... stuff for interactive shells (aliases and terminal stuff mostly)

Ben.


_______________________________________________ Do not post admin requests to the list. They will be ignored. Macos-x-server mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/macos-x-server/email@hidden

This email sent to email@hidden
References: 
 >Re: How to alter system-wide $PATH for non-interactive, non-login bash shells invoked via sshd? (From: Ben Schmidt <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.