Xonsh: echo foo >bar doesn't work

Created on 18 Oct 2016  路  3Comments  路  Source: xonsh/xonsh

Maybe it's different in xonsh than in bash but I type that very frequently and I get:

echo foo >bar
............................................. 
  File "<string>", line None
SyntaxError: <xonsh-code>:1:5: ('code: foo',)
echo foo >bar
     ^
docs newcomer

Most helpful comment

yes this is a place where xonsh separates from bash,
xosh can redirect the streams with words too, for example:
echo foo err>out > file will redirect both stdout and stderr in 'file'.
but if you wanted to redirect to a file named 'out' then it would be very ambiguous

Redirections are arguments that may take filename arguments,
and like every argument in subprocess mode, it's separated at whitespace.

we must add this as a warning or a note in that tutorial section @astronouth7303 linked.

All 3 comments

Nope, that is valid xonsh syntax. Although in general, it's safer to assume xonsh does things different than bash.

Hmm, what's going on with it in this case, then?

Edit: It's because there's no space character after the ">". Urgh...

echo foo > bar # OK
echo foo >bar # not OK
echo foo> bar # not OK
echo foo>bar # not OK

yes this is a place where xonsh separates from bash,
xosh can redirect the streams with words too, for example:
echo foo err>out > file will redirect both stdout and stderr in 'file'.
but if you wanted to redirect to a file named 'out' then it would be very ambiguous

Redirections are arguments that may take filename arguments,
and like every argument in subprocess mode, it's separated at whitespace.

we must add this as a warning or a note in that tutorial section @astronouth7303 linked.

Was this page helpful?
0 / 5 - 0 ratings