Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Bash Initialisation Files (solipsys.co.uk)
118 points by ColinWright on Aug 11, 2012 | hide | past | favorite | 17 comments


Prompted to submit this because of this item:

http://news.ycombinator.com/item?id=4369485


This is a great start but I'd love to know e.g. exactly what qualifies as a login shell and what calls the shell with these various arguments.


Any shell started with a minus as the first character of argv[0] is a login shell e.g. "-bash" is a login shell.

Many things start your shell this way:

  * the "login" command
    e.g. logging on an a virtual console
  * "su -"
  * "sshd"
    e.g. ssh <hostname>
  * xterms, depending on the settings
    e.g. the original xterm if you run "xterm -ls"
    or you run "xterm" with "xterm*loginShell: true"
    in your ".Xdefaults" or ".Xresources"
  * some X initialization scripts,
    e.g. when logging in to a "Default" session via gdm or kdm
   (how exactly this works depends on your distribution
    some explicitly source .profile instead)
With "bash" you can also manually create a login shell using "bash -l" or "bash --login".


Also sudo.

    $ sudo -i
    # tr \\0 \\n </proc/$$/cmdline
    -bash
    #


A side note to mikelward's answer for OSX users: by default Terminal.app starts all shells as login shells[1]. You can easily change this behavior, but it's the default and many people never even know it's set that way. This is different from defaults on many (most?) Linux systems, and so people coming from one direction to the other often become confused about where to put startup information. (I suppose it's not exactly a Linux versus OSX thing. It has more to do with window managers and how you start up your machine. If you log into Gnome, KDE or similar environments though, most terminal windows you start in the GUI are not login shells. So people get used to that behavior.)

[1]: http://cl.ly/If85


Yep. On my Fedora 17 VM:

Gnome Terminal -> Edit -> Profile Preferences -> Title and Command -> Run command as a login shell (off by default)

XFCE Terminal -> Edit -> Preferences -> General -> Run command as a login shell (off by default)

As far as I can find, KDE Konsole doesn't support this option. It never starts login shells. See http://docs.kde.org/development/en/kde-baseapps/konsole/comm...


To me this is where the real complications come in, especially when trying to do something portable.

From comments in http://news.ycombinator.com/item?id=4369485 -

Linux behavior vs. OSX (or, differences between terminal emulators): http://news.ycombinator.com/item?id=4369732

Different behaviors when using ssh et al.: http://news.ycombinator.com/item?id=4369751

Now combine those issues with the chart and you end up with something that is, true- deterministic, but not really useful. In the end, most people end up just having the startup files boil down to the same thing by sourcing their preferred one. And in the end most people don't try to think to much about the login vs. interactive vs. batch vs. posix/sh - even when they should be.


It would be very cool if there was a similar graph for the entire boot process: from grub to init to rc.d/systemd to login to bash.


Not hard to produce - the most difficult bit is finding someone, anyone, who actually has the information!


You can use

    systemctl dot
It shows the dependency graph of your unit files.


It should be noted this is for systems that use Systemd, which as far as I'm aware of, is only Fedora at this stage.


OpenSuse also ships with systemd per default. Other distributions like Arch or Debian support systemd as well.

http://www.bootchart.org/ is also quite interesting to understand the boot process better and profile it.


Ah, I had a suspicion OpenSuse would, as it follows Fedora quite closely. Bootchart is also quite interesting.


Thanks - looks interesting. Not installed on my system - I'll have to go investigate that in my copious free time.


I'm with Henry Spencer on this.

"Those who don't understand Unix are condemned to reinvent it, poorly."


If you want to understand this more, read "Bash Startup Files" and "Interactive Shells" from the Bash Reference Manual.

http://www.gnu.org/software/bash/manual/bashref.html#Bash-St...

http://www.gnu.org/software/bash/manual/bashref.html#Interac...


So where does Git Bash for Windows fall into here?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: