Results 1 to 4 of 4

Thread: Curly brace expansions don't work in Bash scripts

  1. #1
    Join Date
    Jul 2010
    Beans
    5

    Curly brace expansions don't work in Bash scripts

    I'm trying to use a curly brace expansion in a Bash script, but it's not working for me in Ubuntu. It works in other distributions, like Arch, Fedora and Debian, and it works in Ubuntu as well, but only from the command line, not in a Bash script. I've tried it on multiple Ubuntu (10.04) machines, so it's not specific to one configuration. Here's what I did:

    Code:
    mkdir a b
    Now this works:
    Code:
    ls {a,b}
    But if I create a file foo.sh, and put
    Code:
    ls {a,b}
    in it and run it, I get this:
    Code:
    ls: cannot access {a,b}: No such file or directory
    It's not parsing the expansion. Any ideas?

  2. #2
    Join Date
    Jul 2009
    Location
    London
    Beans
    1,480
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Curly brace expansions don't work in Bash scripts

    Hi,
    its because its not bash that is executing the script, it is dash.
    do
    Code:
    ls -l /bin/sh
    and you'll see that /bin/sh is a symlink to the dash shell.
    To run the script under bash put in a #! /bin/bash shebang

  3. #3
    Join Date
    Feb 2010
    Location
    Texas, USA
    Beans
    63
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Curly brace expansions don't work in Bash scripts

    I'm not on my Ubuntu box right now but try:
    Code:
    ls "{a,b}
    or
    Code:
    ls '{a,b}'
    Make sure the first line of the bash script is
    Code:
    #!/bin/bash
    Help yourself: Use the forum search
    Help us help you: Use descriptive titles and detailed posts.
    Help others: Mark threads as [Solved] once it is.
    Twitter Facebook Blog

  4. #4
    Join Date
    Jul 2010
    Beans
    5

    Re: Curly brace expansions don't work in Bash scripts

    It was dash. This is a little bit of a problem, because I'm using curly brace expansions in an Autoconf script, and Autoconf doesn't let you force a specific shell (the user must do it manually when running configure).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •