Search code examples
pythonbashcommandescapingcurly-braces

What do double curly braces do in a bash command?


I am refactoring a script and I'm seeing this:

/bin/bash -c 'rm -rf directory/{{..?*,.[!.]*,*}}'

Googling "bash double curly braces" is strangely not getting my anywhere so far. What does this code do?

EDIT: I didn't include enough details, apparently. It's actually a python command that was using format(), so the double curly braces were actually single curly braces being escaped for that.

subprocess.check_output(['/bin/bash', '-c', 'rm -rf {0}/{{..?*,.[!.]*,*}}'.format('directory')]

@thatotherguy nailed it in the comments.


Solution

  • Sometimes the double curly appears when passing a bash script in a GitLab or GitHub runner for example

      - name: Set selected color
        run: echo '::set-output name=SELECTED_COLOR::green'
        id: random-color-generator
      - name: Get color
        run: echo "The selected color is ${{ steps.random-color-generator.outputs.SELECTED_COLOR }}"
    

    https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions