1

So I have some experience with linux and I was always wondering if it is possible to modify the terminal so that it executes a different interpreter (like python) rather than the default shell interpreter (like sh or bash).

(Note that this is not just "Where do I change my shell?" or "How to change from csh to bash as default shell". This is about running things that are not shells, per se, but are interpreters. I give python as an example to make things clearer, but I could have easily said php or any other interpreter.)

Is this possible, and if so, how would I do it?

JdeBP
  • 68,745
Hamdi
  • 13
  • And that's what the referred question explains so you can add the path to /etc/shells and use chsh to change the interpreter to a user or is that wrong ? – Hamdi Jun 04 '20 at 13:13
  • 2
    That is not wrong but there are reasons why python is not listed in /etc/shells. These reasons don't go away by just adding it. Python is not prepared to be a login shell. You lose the environment setup. – Hauke Laging Jun 04 '20 at 13:31
  • I agree that it is not a duplicate, given that it's not asking about substituting one shell for another. But it is rather broad, as it hasn't specified whether this means changing what a GUI terminal emulator runs or changing what is run after TUI login on a virtual or real terminal. The problem is the ambiguous "modify the terminal". Has the questioner made the usual far-too-often-made error of conflating terminals with something else? Or does xe really mean modifying the settings of a terminal emulator program? – JdeBP Jun 04 '20 at 16:44

3 Answers3

0
chsh

lets you switch your login-shell (restrictions apply, see also /etc/shells)

stoney
  • 1,055
0

As has been mentioned in the comments and the first answer: You can change only (at least with chsh) to those shells which are listed in /etc/shells. If you manually force a different shell into /etc/passwd (or a different user data base) then it may be run by login (I haven't tried that) but that would not solve the problems which are the reason for e.g. python not being listed in /etc/shells.

A login shell has certain tasks, mainly setting up the environment for the user. Thus only login shells read /etc/profile.

possible compromise

You could create a link (symlink or hard link, I currently habe no opinion which is better) to a regular shell like

cd /bin
ln -s bash bash-python

and add /bin/bash-python to /etc/shells and set it as default shell for a user. In /etc/profile (or /etc/bash.bashrc) you can check whether the shell has been started with this name and execute python:

[[ $0 =~ bash-python ]] && exec python
# or
[[ $0 =~ bash-python ]] && python

I am not convinced yet which is better. Maybe the variant without exec for wtmp logging but I am not sure whether that is done by the login shell; maybe it's PAM after the login shell exists.

Hauke Laging
  • 90,279
  • A login shell is not required to be a prompt-read-execute-loop program, or have dealings in environment variables, and over the years there have been many people who have set up all sorts of things as login shells, from bespoke menu systems through dedicated single applications to BBSes and UUCP. – JdeBP Jun 05 '20 at 06:22
0

Yes, it’s possible. One approach is to configure your terminal appropriately; the specifics depend on your terminal emulator.

In GNOME Terminal, you’d edit the command in whatever profile you want:

GNOME Terminal preferences showing the Command tab

This allows you to open terminals with the chosen command instead of your default shell:

GNOME Terminal running IPython

This is less invasive than changing your default shell outright (which would also require administrative assistance if you’re not using one of the shells in /etc/shells).

Stephen Kitt
  • 434,908