3 ms·
(re: Bash-vs-OS integration) bash is a programming language like any other, and you could use anything with a REPL as your shell. Python should do. In fact, I'
by nothrabannosir 8y ago
(re: Bash-vs-OS integration)
bash is a programming language like any other, and you could use anything with a REPL as your shell. Python should do. In fact, I'll try it right now..
Yes, it works. Just sudo chsh -s /usr/bin/python <username> and off you go.
Once you start doing this for a bit, you'll notice that the Python REPL is an incredibly poor UI for repeated execution of subprocesses. It is very elaborate. Having to constantly wrap your strings in quotes, calling subprocess modules, exec, painstaking handing of streams, etc.
Then you start looking for a language that has better syntax for calling external programs.. hmm...
Bash. Or zsh, or ksh, etc. These languages excel at it. But that's all they are: programming languages that happen to be super easy to use when it comes to starting external programs.
This is why it makes little sense to bind them to the OS. As far as the OS is concerned: there is no Bash. Just like there is no Python. There is just syscalls.
- meditate 8y agoYou may be interested in xonsh, a shell that supports both python and bash-like expressions: https://xon.sh/ https://xon.sh/
- nurettin 8y agois this like fish?
- leadingthenet 8y agoIt's pretty much like fish, but with Python goodness.
- wlib 8y agoThank you for this
- klibertp 8y ago> Python REPL is an incredibly poor UI for repeated execution of subprocesses Python REPL, even with recent additions of TAB completion, is a poor REPL, period. IPython, on the other hand, offers a much better programming environment than shell while still allowing easy access to most of the things you mention. Example: In [1]: from pathlib import Path In [2]: file = Path("~/.sbclrc").expanduser().read_text() In [3]: !echo "$file" | awk '!/^;;/' # EDIT: to clarify, this shows passing # Python variable to a shell pipeline. #-quicklisp (let ((quicklisp-init (merge-pathnames quicklisp/setup.lisp (user-homedir-pathname)))) (when (probe-file quicklisp-init) (load quicklisp-init))) All things considered, between !, %, %% and /, IPython is a decent shell. I was using it for a few years as my main shell, actually - its QT Console implementation specifically. I was working on Windows back then, PowerShell didn't exist yet, and `cmd.exe` was... well, exactly the same as today. TLDR: a shell is just a REPL with a few conveniences for specific tasks. Re-implement these and suddenly any REPL becomes a workable shell.
- palunon 8y ago> In [3]: !echo "$file" | awk '!/^;;/' That's Bash (or at least sh). Which excels at piping the output of programs into other programs, and pay that cost for everything else.
- dbdjfjrjvebd 8y agoYep. IPython lets you execute bash.
- klibertp 8y agoYeah, that's what I mean by "easy access" - you're working with Python, but if you want to do something that Python is not well-suited for[1] - like easily piping something through many programs - you can do it simply by adding `!` at the beginning of your pipeline, right there in the REPL. It's actually the same philosophy that shells use: in bash you frequently invoke sed, awk, grep, etc. because it's easier than writing the same directly in the shell. In IPython, you invoke bash to do piping, because it's easier than connecting a host of subprocesses' stdins/stdouts in Python. So again, there are some things you expect from your shell, and as long as you get those things (no matter how), you can use any REPL as a shell without problems. [1] because of syntax or lack of library or something like that
- wlib 8y agoPiping program output is just function composition. The downside is that it works over expensive system processes, and data must be serialized. It's a fragile system where instead of using built-in functions, we use "standard" executables.
- yesenadam 8y agoI think, rather, function composition is just piping program output.