Xonsh: /usr/bin/cut: the delimiter must be a single character with cut -d';'

Created on 26 Apr 2020  路  5Comments  路  Source: xonsh/xonsh


try to run

cat ~/.zsh_history  | cut -d';' -f2-

and got the error:
/usr/bin/cut: the delimiter must be a single character

xonfig

$ xonfig

Expected Behavior

Should show the trimmed command from my zsh history, like if I run it in zsh or bash

Current Behavior

show the above error

reproduce

enter

cat ~/.zsh_history  | cut -d';' -f2-

in a xonsh terminal

Most helpful comment

I found out the solution while writing the issue.
zsh/bash allow -d';' without space and xonsh need a space. I was used to skip the space.

All 5 comments

I found out the solution while writing the issue.
zsh/bash allow -d';' without space and xonsh need a space. I was used to skip the space.

cut --delimiter=';' won't work neither, I guess I understand why, but it's still a little bit disappointing ( first time using xonsh )

Hi @sucrecacao! You expect that ';' works the same way as in bash/zsh but no. In xonsh arg=';' is one whole argument but in bash the arg=';' argument will be parsed and the result will be arg=;.

The working examples of your command:

cat ~/.zsh_history  | cut -d ';' -f2
cat ~/.zsh_history  | cut -d ";" -f2
cat ~/.zsh_history  | cut "-d;" -f2   # thanks to @laloch
cat ~/.zsh_history  | cut -d@(';') -f2
cat ~/.zsh_history  | cut --delimiter ';' -f2-
cat ~/.zsh_history  | cut --delimiter ";" -f2-
cat ~/.zsh_history  | cut "--delimiter=;" -f2-     # thanks to @laloch
cat ~/.zsh_history  | cut --delimiter=@(';') -f2-

To understand why your try is not working try to use $XONSH_TRACE_SUBPROC:

> $XONSH_TRACE_SUBPROC=True

> cat ~/.zsh_history  | cut --delimiter=';' -f1 o> /dev/null e> /dev/null  
TRACE SUBPROC: (['cat', '/home/user/.zsh_history'], '|', ['cut', "--delimiter=';'", '-f1', '>', '/dev/null'])

> cat ~/.zsh_history  | cut --delimiter=@(';') -f1 > /dev/null
TRACE SUBPROC: (['cat', '/home/user/.zsh_history'], '|', ['cut', '--delimiter=;', '-f1', '>', '/dev/null'])

As you can see in the first trace we have 3 charecters (';') and the one (;) in the second. This is the cause why cut returns the delimiter must be a single character.

To compare it with bash you can use set -x command:

bash$ set -x 
bash$ cat ~/.zsh_history  | cut --delimiter=';' -f1 1> /dev/null
+ cut '--delimiter=;' -f1
+ cat /home/pc/.zsh_history

You also can read:

The answer is above and the issue could be closed.

The following should work as well:

$ cat ~/.zsh_history | cut "-d;" -f2
Was this page helpful?
0 / 5 - 0 ratings

Related issues

OJFord picture OJFord  路  5Comments

jeremyherbert picture jeremyherbert  路  5Comments

daniel-shimon picture daniel-shimon  路  5Comments

OJFord picture OJFord  路  6Comments

blueray453 picture blueray453  路  5Comments