0

I came across this problem a few weeks ago but I thought it was my system acting up. But after a couple of investigations, I believe this could be a bug. Or maybe I am wrong. When attempting to echo or touch multiple files on CentOS7 such as: echo file{a..c}.txt doing this on CentOS7 returns file{a..c}.txt but performing the same command on RHEL7 returns: filea.txt fileb.txt filec.txt

Is anyone else having the same issue?

  • 2
    check shell & environment variables may explain syntax difference in results – francois P Feb 23 '18 at 21:45
  • Do you have the same minor revisions (say 7.0 vs 7.4), same user (say root vs non-root, and subsequently same shell), same host virtualization (say inside docker container vs physical host). If absolutely everything is the same, then it's at least strange because CentOS builds from the same source packages... – Nopius Feb 24 '18 at 4:28
1

You would see this behavior if your shell on the CentOS system was dash, which does not expand brace ranges like that:

$ for shell in bash dash ksh
> do
> echo in $shell:
> $shell -c 'echo file{a..c}.txt'
> done
in bash:
filea.txt fileb.txt filec.txt
in dash:
file{a..c}.txt
in ksh:
filea.txt fileb.txt filec.txt

From the comments you're using zsh on the CentOS system. I can reproduce the behavior by setting the ignorebraces shell option:

$ set -o|grep ignorebraces
ignorebraces          off
$ echo {1..3}
1 2 3
$ set -o ignorebraces
$ echo {1..3}
{1..3}
$ set +o ignorebraces
$ echo {1..3}
1 2 3
1

This depends on what shell you are using on the various systems.

Brace expansion is an extension to the POSIX standard for the shell and not every shell implements it. Those who do may do it in different ways.

The dash shell does not implement brace expansion:

$ echo {0..9}
{0..9}
$ echo {1,2,3}
{1,2,3}

The pdksh shell (as found on OpenBSD) implements brace expansion, but not for ranges:

$ echo {0..9}
{0..9}
$ echo {1,2,3}
1 2 3

The bash, zsh, and ksh93 shell implements ranges (both numerical and alphabetic)

$ echo {0..9}
0 1 2 3 4 5 6 7 8 9
$ echo {1,2,3}
1 2 3
  • I am actually using bash on rhel7 and zsh on Centos7 could that be the reason why the brace expansion works on rhel and not Centos ? – christian x Feb 24 '18 at 12:54
  • @christianx Hmm... I explicitly tested with zsh without problems. I'm not at a computer now (on the phone). What version of zsh are you using? It ought to support brace expansion out of the box. – Kusalananda Feb 24 '18 at 12:57
  • zsh --version returns: zsh 5.0.2 – christian x Feb 24 '18 at 13:08
  • @christianx I'm on 5.4.2 and I can't reproduce what you're seeing on CentOS on my machine with this version of zsh. I also do not have access to an older version to test with. I can't find anything relevant in the release notes for the releases between your and my version of the shell either... – Kusalananda Feb 24 '18 at 17:36
  • 1
    @christianx is it possible that you've disabled brace expansion in zsh? set -o ignorebraces would do it. – Jeff Schaller Feb 24 '18 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.