try to run
cat ~/.zsh_history | cut -d';' -f2-
and got the error:
/usr/bin/cut: the delimiter must be a single character
$ xonfig
Should show the trimmed command from my zsh history, like if I run it in zsh or bash
show the above error
enter
cat ~/.zsh_history | cut -d';' -f2-
in a xonsh terminal
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
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.