I'd like to replace bash with IPython on my system, so that even files like .profile are in Python rather than shell script.

I have some confusion on the topic, even though asking a few questions on the matter. Here are the questions I have asked previously:

1) How can I replace bash with Python?

From the answer to that question, I learned how to automatically replace bash with IPython after log in (note that it still uses .profile written in shell script).

2) .profile is written in shell script — can I instead make my system understand that I want it to execute a Python script instead?

From the answer to that question, I learned that .profile file is "sourced" rather than "executed" -- that is, the lines in .profile are run one by one, as if one were typing them into the shell.

So, my question now is: how do I get my base system shell to be IPython, so that it can source .profile files with IPython magics/Python written inside them? For example, I'd like to write my .profile file using IPython magics/Python.

  • 3
    iPython is not a shell, it is a Python interpreter / interactive environment. There is no reasonable way to do what you are asking. You can have your shell profile or rc file automatically start iPython for you, but that will not make it your shell; it will just be a program that your shell starts for you. – DopeGhoti Dec 10 '15 at 17:51
  • @DopeGhoti see: stackoverflow.com/a/209562/3486684 – user89 Dec 10 '15 at 17:52
  • There is the fledgeling pysh shell which can be found at github.com/yunabe/pysh which may do what you are looking for. – DopeGhoti Dec 10 '15 at 17:58
  • @DopeGhoti Did you also read the answer I linked to? – user89 Dec 10 '15 at 18:30
  • 1
    I did. It does a very good job of explaining that Python can in fact do nearly every thing a shell does, but that does not negate the fact that Python is a scripting language and not a bona fide shell. I would not be shocked to see some Pythonic flavor of csh or tcsh sometime down the line, but that day is not today. – DopeGhoti Dec 10 '15 at 18:40

If you want to have Python launched as your default shell by the login(1) process, you can change your shell in the /etc/passwd file using the command:

usermod -s /usr/bin/python yourusername

The.profile script will still not be executed. This filename/location is hardcoded into bash(1). If you really want this, you could set up a shebang (#!) script that is interpreted by python and make this your user shell. You can then enter interactive mode from the script using code.interact().

This won't work very well though (if at all). Python's interactive mode doesn't perform most of the functions of a shell (e.g. job control) and os.system won't help, as your system shell is now Python.

| improve this answer | |
  • Thanks for this answer! One thing that remains unclear to me is whether you mean "IPython" when you refer to "Python"? – user89 Dec 10 '15 at 19:02
  • 1
    This isn't recommended, unless you also update /etc/shells. (Assuming things have changed recently or configured specially...) if your login shell is not listed in /etc/shells, you won't be able to login. – Otheus Dec 17 '15 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.