How to enter escape character in a positional string argumentfrom the command line?
gene heskett
gheskett at shentel.net
Wed Dec 21 11:55:54 EST 2022
On 12/21/22 11:22, Chris Angelico wrote:
> On Thu, 22 Dec 2022 at 03:11, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>>
>> Lars Liedtke <lal at solute.de> writes:
>>> Or you could have "native" bash ($SHELL) with WSL.
>>
>> In this newsgroup, it would actually be obvious to use Python.
>
> Less obvious than you might think - partly because bash is just so
> dang good that it's really really hard to outdo it :) Sure, bash has a
> lot of weird and wonky edge cases, but it's an incredibly practical
> shell to use.
>
When you make a statement like that, Chris, you should also note that
every single one of those "wonky edge cases" is documented down to the
last dotted i. Bash's docs will kill a good sized pulp tree, needing
around a ream of paper to print on a duplex printer. I know, I did it
around a decade ago. If you like to write scripts, having a dead tree
copy of the docs at your elbow in incredibly useful. That huge man page
does not cover it like the printed docs do.
>> When commands are typed manually, this might be a bit verbose,
>> though. I mean
>>
>> os.chdir( r'C:\EXAMPLE' )
>>
>> versus
>>
>> CD C:\EXAMPLE
>
> Exactly. What's good for a programming language is often not good for a shell.
>
>> class PythonShell( cmd.Cmd ):
>>
>> intro = 'Welcome to the Python shell. Type help or ? to list commands.\n'
>> prompt = '(Python) '
>> file = None
>>
>> def do_cd( self, arg ):
>> 'change directory: CD C:\EXAMPLE'
>> os.chdir( *parse( arg ))
>>
>> def do_bye( self, arg ):
>> 'Exit: BYE'
>> print( 'Thank you for using the Python Shell!' )
>> return True
>
> Sure, you can always create your own shell. But I think you'll find
> that, as you start expanding on this, you'll end up leaning more
> towards "implementing bash-like and/or cmd-like semantics in Python"
> rather than "creating a Python shell". Shells, in general, try to
> execute programs as easily and conveniently as possible. Programming
> languages try to stay inside themselves and do things, with subprocess
> spawning being a much less important task.
>
> Fun challenge: see how much you can do in bash without ever forking to
> another program. And by "fun", I mean extremely difficult, and by
> "challenge" I really mean "something you might have to do when your
> system is utterly hosed and all you have available is one root shell".
>
> It's amazing how far you can go when your hard drive has crashed and
> you desperately need to get one crucial login key that you thought you
> had saved elsewhere but hadn't.
>
> ChrisA
Cheers, Gene Heskett.
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
- Louis D. Brandeis
Genes Web page <http://geneslinuxbox.net:6309/>
More information about the Python-list
mailing list