Experimental Project Attempts a Python Virtual Shell for Linux

'Long-time Slashdot reader CJSHayward shares "an attempt at Python virtual shell." The home-brewed project "mixes your native shell with Python with the goal of letting you use your regular shell but also use Python as effectively a shell scripting language, as an alternative to your shell's built-in scripting language... I invite you to explore and improve it!"
From the web site: The Python Virtual Shell (pvsh or 'p' on the command line) lets you mix zsh / bash / etc. built-in shell scripting with slightly modified Python scripting. It's kind of like Brython [a Python implementation for client-side web programming], but for the Linux / Unix / Mac command line...
The core concept is that all Python code is indented with tabs, with an extra tab at the beginning to mark Python code, and all shell commands (including some shell builtins) have zero tabs of indentation. They can be mixed line-by-line, offering an opportunity to use built-in zsh, bash, etc. scripting or Python scripting as desired. The Python is an incomplete implementation; it doesn't support breaking a line into multiple lines. Nonetheless, this offers a tool to fuse shell- and Python-based interactions from the Linux / Unix / Mac command line.' -- source: https://developers.slashdot.org/story/23/10/29/1610218 Cheers, Peter -- Peter Reutemann Dept. of Computer Science University of Waikato, Hamilton, NZ Mobile +64 22 190 2375 https://www.cs.waikato.ac.nz/~fracpete/ http://www.data-mining.co.nz/

On Mon, 30 Oct 2023 08:40:51 +1300, Peter Reutemann quoted:
'The home-brewed project "mixes your native shell with Python with the goal of letting you use your regular shell but also use Python as effectively a shell scripting language, as an alternative to your shell's built-in scripting language...'
Not so sure this is a good idea. The way I see it, there is a fundamental dichotomy between shell/command languages and programming languages (including “scripting” languages). In a shell language, everything you type is assumed to be a literal string, unless you use special substitution sequences. E.g. ls -l thingy “give me information about the file/directory named ‘thingy’”, vs. ls -l $thingy “give me information about the files/directories whose names are in the value of the variable ‘thingy’”. Whereas in a programming language, everything is assumed to be a language construct, and every unadorned name is assumed to reference some value/object, so you need quote marks to demarcate literal strings, e.g. os.listdir(thingy) “return a list of the contents of the directory whose name is in the variable ‘thingy’”, vs. os.listdir("thingy") “return a list of the contents of the directory named ‘thingy’”. The point being that, in regular use, most of the things you type at a shell command line are in fact literal strings, with only occasional use of variables and other substitution constructs; such substitutions happen more commonly in script files. So if you want to use a more programming-oriented language like Python as a command line, then you will end up typing literal quotes a lot more often, which will likely become an annoyance.
participants (2)
-
Lawrence D'Oliveiro
-
Peter Reutemann