/etc/profile always does a "cd $HOME"

René Berber rberber@prodigy.net.mx
Mon May 23 04:59:00 GMT 2005


Sven Köhler wrote:

> i'd like to use cygwin from a normal windows-app. The problem is, that i
> need a login-shell, so that all environment-vars are properly set. The
> problem: bash -li always changes the current workdir!

That's not a problem, it's a feature.

> IMHO, executing "bash -li" shouldn't change the workdir.

Wrong!

> No other system i know does that.

Not true, "bash -li" works the same in any system that runs bash.  You are
probably thinking of running "bash" without the parameter... that execution
doesn't change the current location.

In fact, if you login into any system using any shell you login into your home
dir.  That's the idea that the -l or --login parameter make explicit.

> Script may rely on that behaviour.
> 
> /etc/profile contains the like
>   cd "$HOME"
> 
> That line cannot easily be removed. Starting the Cygwin-Link installed
> by the setup wouldn't cd to ~ anymore. This behaviours is liked by most
> users i guess (including my own).
> 
> Any suggestions, how the situation could be improved?

Yep, read the bash manual, learn to use bash.

Quote from man bash:

       -i        If the -i option is present, the shell is interactive.
       -l        Make bash act as if it had been invoked as a login shell (see
                 INVOCATION below).
...
INVOCATION
       A  login shell is one whose first character of argument zero is a -, or
       one started with the --login option.

       An interactive shell is one started without  non-option  arguments  and
       without  the  -c  option  whose standard input and output are both con-
       nected to terminals (as determined by isatty(3)), or one  started  with
       the  -i  option.   PS1 is set and $- includes i if bash is interactive,
       allowing a shell script or a startup file to test this state.

       The following paragraphs describe how bash executes its startup  files.
       If  any  of  the files exist but cannot be read, bash reports an error.
       Tildes are expanded in file names as described below under Tilde Expan-
       sion in the EXPANSION section.

       When  bash is invoked as an interactive login shell, or as a non-inter-
       active shell with the --login option, it first reads and executes  com-
       mands  from  the file /etc/profile, if that file exists.  After reading
       that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
       in  that order, and reads and executes commands from the first one that
       exists and is readable.  The --noprofile option may be  used  when  the
       shell is started to inhibit this behavior.
...
       When bash is started non-interactively, to  run  a  shell  script,  for
       example, it looks for the variable BASH_ENV in the environment, expands
       its value if it appears there, and uses the expanded value as the  name
       of  a  file to read and execute.  Bash behaves as if the following com-
       mand were executed:
              if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
       but the value of the PATH variable is not used to search for  the  file
       name.
...
       When bash is started in posix mode, as with the  --posix  command  line
       option, it follows the POSIX standard for startup files.  In this mode,
       interactive shells expand the ENV variable and commands  are  read  and
       executed  from  the  file  whose  name is the expanded value.  No other
       startup files are read.
...
-- 
René Berber


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list