9

Do I have to do any configuration to start brace expansion? When I run mkdir {1..10}, it just creates a dir naming {1..10}.

  • mkdir {1..10} works for me, it creates ten dirs. – suspectus Sep 29 '13 at 7:44
  • 2
    I advise to add echo ${SHELL} to render this question able to get a useful answer. – dan Dec 26 '15 at 12:46
10

While brace expansion like {1,2} originates in csh in the late 70s, and found its way to Bourne-like shells in bash/zsh/pdksh in the late 80s, early 90s, the {n1..n2} variant came later first in zsh in 1995 (2.6-beta4).

bash copied it in 2004 (3.0) and ksh93 in 2005 (ksh93r).

Probably the shell you're trying this in is neither of those or is an older version of bash and ksh93.

  • We should as about what kind of shebank shell he used. /me suspects it's #!/bin/sh... – polemon Sep 29 '13 at 8:25
  • 3
    @polemon, That would not necessarily help. For instance, on some systems /bin/sh is bash or ksh93. – Stéphane Chazelas Sep 29 '13 at 8:34
  • 2
    I actually think it would: depending on the invocation, shells invoked as /bin/sh act as the historic sh (it's what the bash man page says anyway). Haven't checked ksh's man page, but I'm sure it'll behave accordingly. – polemon Sep 29 '13 at 8:44
  • 1
    @user43312: why are you still using RH9? It has been unmaintained for many many years. AS Stephane wrote it is a feature of recent bash versions. So it's very unlikely that your bash version supports it. You can check the version using bash --version. And just to be sure check if you are running a bash shell by checking the $SHELL variable or simply running ps. To use this feature you might try to start a zsh shell (zsh) first. Anothher workaround would be to use something like "mkdir $(seq 1 10)". – Bram Sep 29 '13 at 11:10
  • 1
    @polemon The startup behaviour of another shell (ie. which files it sources upon startup), not mimicry of another shell. – Chris Down Sep 29 '13 at 14:36
4

{x..y} Range brace expansion is implemented in bash 3.0-alpha. To help us and yourself, please show your echo "$BASH_VERSION" output.

Then the answer: If mkdir {1..10} creates a dir with the name {1..10} then you are using a bash version prior bash 3.0-alpha. In that case you can use a for loop construction as:

for ((i=1;i<=10; i++)); do mkdir "$i"; done

1

Check your Bash version:

$ bash -version
GNU bash, version 4.1.7(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

Also check that mkdir hasn't been aliases in some strange way:

$ alias |grep mkdir
alias md='mkdir'

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.