11

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}.

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

3 Answers 3

12

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.

12
  • We should as about what kind of shebank shell he used. /me suspects it's #!/bin/sh... Commented Sep 29, 2013 at 8:25
  • 3
    @polemon, That would not necessarily help. For instance, on some systems /bin/sh is bash or ksh93. Commented Sep 29, 2013 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. Commented Sep 29, 2013 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)". Commented Sep 29, 2013 at 11:10
  • 1
    @polemon The startup behaviour of another shell (ie. which files it sources upon startup), not mimicry of another shell. Commented Sep 29, 2013 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' 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.