StackExchange Answers: Shells

Sometimes a Stackoverflow answer is so good that it helps me understand something I had kind of given up on. The distinctions of login and interactive shells are a good example. Some ressources had pointed me to the INVOCATION section of the bash man page. Here’s the explanation of what login and interactive shells are:

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 error are both connected 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.

I’m sure it’s correct and proper. From the perspective of someone trying to understand when .bashrc is invoked, it’s also absurdly unhelpful. Askubuntu user terdon to the rescue.

They just provide examples of each of the four combinations (and two binary tests that will tell you if the shell you’re in is login/interactive or nor) but from those examples, the defining characteristics become so much clearer. A shell is a login shell if I changed user when entering it be that by using su, ssh or logging in on a tty. An interactive shell is basically anything with a prompt and a non-interactive one is running something scripted. The combinations are then as follows:

ExamplesInteractive shellNon-interactive shell
Login shellTTY, su -, sshPiping commands into ssh
Non-login shellA terminal emulator, starting a shell within a login shellScripts

I’m not summarizing to replace the answer, just to check that I understand. terdon’s examples do a much better job of explaining it – go have a read.

Stackexchange Answers: Systemd and PIDs

Systemd tracks PIDs. This is kind of obvious but I never thought to investigate before today. These two commands have been and I suspect, will be, very useful:

journalctl _PID = 1234

Get info on anything logged by the process in question. Technically, I suppose (?) it shouldn’t tell you anything that systemctl -u whatever.service doesn’t but it helped me get the exact error that caused the service not to work. Thanks, Rahul Khimasia.

systemctl status 1234

How exactly does pulseaudio get started on your desktop? Simply use htop to find the PID and ask systemctl for a status on the it and you will get told what systemd unit is associated with it. session-27.scope, it seems. Didn’t even know there was such a thing as ‘scopes’. Thanks, larsks.