Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
    
mkdir {1..10} works for me, it creates ten dirs. –  suspectus Sep 29 '13 at 7:44

3 Answers 3

up vote 6 down vote accepted

While brace expansion like {1,2} originates in csh in the late 70s, and found its way to Bourne-like shells in ksh in the late 80s, the {n1..n2} variant came a lot 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.

share|improve this answer
    
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
1  
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

{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

Hope it helps.

share|improve this answer

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'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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