Fish-shell: sub/gsub/gensub function of awk/gawk not works properly in FISH

Created on 31 Oct 2016  ·  3Comments  ·  Source: fish-shell/fish-shell

  • [x] Have you checked if problem occurs with fish 2.3.1?
  • [ ] Tried fish without third-party customizations (check sh -c 'env HOME=$(mktemp -d) fish')?

fish version installed (2.3.1):

OS/terminal used:
Ubuntu 16.04 server

Talk about the the issue here.
awk or gawk sub function not works properly. The results are different from awk in bash.

Reproduction steps

In fish, use following command, it gave nothing.

gawk 'BEGIN{a = "abc def"; b = gensub(/(.+) (.+)/, "\\2 \\1", "g", a); print b}'

In bash, the same command gave the right output def abc

question

Most helpful comment

The issue here is the "\" in quotes. Fish will still strip one of the two, while bash will leave it. See for yourself with e.g. echo gawk ....

Add one more - "\\\2 \\\1" and it works.

I think that this is expected (there are other differences in quoting behavior, and often with good reason), but I'll have to consult our docs some more.

All 3 comments

The issue here is the "\" in quotes. Fish will still strip one of the two, while bash will leave it. See for yourself with e.g. echo gawk ....

Add one more - "\\\2 \\\1" and it works.

I think that this is expected (there are other differences in quoting behavior, and often with good reason), but I'll have to consult our docs some more.

Also, what does this have to do with math?

@faho Thank you! It works!
Sorry for the confusion of math which comes from the issue template.

Was this page helpful?
0 / 5 - 0 ratings