Ask Your Question
0

How to incorporate brace expansion in a script using /bin/dash?

asked 2023-05-17 09:05:54 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-17 09:29:02 +0000

huitzilopochtli gravatar image

Here's an example of how to use brace expansion in a script using /bin/dash:

#!/bin/sh

# create directories using brace expansion
mkdir {test1,test2,test3}/{dir1,dir2}

# create files using brace expansion
touch {test1,test2,test3}/file{1..5}.txt

In this script, we're creating three directories with subdirectories within them using brace expansion (test1/dir1, test1/dir2, test2/dir1, etc.). We're also creating files in each of these directories using brace expansion (file1.txt, file2.txt, etc.).

Note that in dash (which is a minimal shell), brace expansion is not enabled by default. To enable it, you can set the set -B option at the beginning of your script.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-17 09:05:54 +0000

Seen: 14 times

Last updated: May 17 '23