Live data from Hacker News

Xonsh, a Python-ish, Bash-compatible shell language and command prompt

xonsh.org

11–20 of 63 posts

Re: Xonsh, a Python-ish, Bash-compatible shell language and command prompt

#11

Is there a way to switch explicitly between Python and Bash mode? The "ls -l" example makes me pretty worried that this could mess up basic bash scripts that already work just by defining a variable like "ls" and forgetting about it, or forgetting where it's defined. It's a great idea, but there's a lot of room for stuff breaking that worries me.

You can use an uncaptured subprocess to run a command explicitly in bash mode. I'm unsure how you think xonsh would break a bash script, though. When you run a script in xonsh it's still going to be interpreted by whatever is declared in the script's shebang. Just like you can run a perl script from bash, you can run a bash script from xonsh. E.G.

  $ ls='foo'
  $ cat test.sh 
  #!/bin/bash
  ls ~
  $ print(ls)
  foo
  $ ./test.sh 
  bin    C:\nppdf32Log\debuglog.txt  foo	       initrd.img.old  lost+found  opt	 run   sys  var
  boot   dev			   home        lib	       media	   proc  sbin  tmp  vmlinuz
  cdrom  etc			   initrd.img  lib64	       mnt	   root  srv   usr  vmlinuz.old

Re: Xonsh, a Python-ish, Bash-compatible shell language and command prompt

#12

Is there a way to switch explicitly between Python and Bash mode? The "ls -l" example makes me pretty worried that this could mess up basic bash scripts that already work just by defining a variable like "ls" and forgetting about it, or forgetting where it's defined. It's a great idea, but there's a lot of room for stuff breaking that worries me.

Presumably the shebang at the start of your script would cause it to be executed by bash directly.

Re: Xonsh, a Python-ish, Bash-compatible shell language and command prompt

#13
post #8

This is great. When dealing with bash stupid-isms I've always thought it would be awesome to have a shell with Python syntax. The tough part is figuring out how to combine Python with "normal" shell commands in a clean, intuitive manner but it looks like Xonsh has gone a long way towards solving that! Just installed on my personal Macbook. Will see how it goes.

I agree, this is awesome. I hate dealing with bash but it's pretty common when you're DevOps.

Re: Xonsh, a Python-ish, Bash-compatible shell language and command prompt

#16
post #8

This is great. When dealing with bash stupid-isms I've always thought it would be awesome to have a shell with Python syntax. The tough part is figuring out how to combine Python with "normal" shell commands in a clean, intuitive manner but it looks like Xonsh has gone a long way towards solving that! Just installed on my personal Macbook. Will see how it goes.

You could already do some minimal shell-like scripting with ipython[1]. Just put your ipython-flavored script in a file with .ipy extension an call it with ipython, or just use #!/usr/bin/ipython as a shebang.

  #!/usr/bin/ipython
  files = !ls
  for f in files:
    print(f)

That being said, it is a bit clunky to use since it's not a proper shell, so xonsh is definitely a very welcome improvement.

[1]: http://ipython.org/ipython-doc/stable/interactive/shell.html

Re: Xonsh, a Python-ish, Bash-compatible shell language and command prompt

#17

Is there a way to switch explicitly between Python and Bash mode? The "ls -l" example makes me pretty worried that this could mess up basic bash scripts that already work just by defining a variable like "ls" and forgetting about it, or forgetting where it's defined. It's a great idea, but there's a lot of room for stuff breaking that worries me.

I don't think you would replace /bin/bash with this, but rather switch to it as your interactive shell, using "chsh". On FreeBSD, for example, the default shell is /bin/tcsh but scripts are usually written for /bin/sh (with a shebang line).

Even if this thing can execute unmodified bash scripts (can it?), it seems to me that would be missing the point, which is to avoid the horror of writing complex bash scripts. When I start writing something in bash, because of those few things it makes so easy (e.g. running subprocesses), I usually regret it as the script grows. If xonsh can make those things just as easy, every script can be written in the right language – which is of course Python :) – from the start.

Re: Xonsh, a Python-ish, Bash-compatible shell language and command prompt

#19
I genuinely wish there was an alternative that could gain enough traction to reach critical mass and hopefully start shipping with operating systems. I've never bothered to learn bash because it was always so damned confusing, and I just couldn't get over the idiosyncrasies when playing around with it. I wouldn't mind putting in time to learn something new and actually user-friendly.
Post reply on HN