LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How do I use mkdir{bin,usr,etc} in a script (https://www.linuxquestions.org/questions/programming-9/how-do-i-use-mkdir%7Bbin-usr-etc%7D-in-a-script-4175694399/)

voncloft 04-28-2021 05:46 AM

How do I use mkdir{bin,usr,etc} in a script
 
Hi when I try to use the following code in bash

mkdir{bin,usr,etc} I am left with a folder that is literally named: {bin,usr,etc} instead of 3 different folders.


Any ideas?

TenTenths 04-28-2021 06:34 AM

Works just fine for me:

Code:

$ cat test.sh
#!/bin/bash

mkdir {bin,usr,etc}

$ ./test.sh

$ ls
bin  etc  test.sh  usr


pan64 04-28-2021 06:41 AM

would be nice to see what did you execute - exactly.
Is this your homework?

EdGr 04-28-2021 10:39 AM

Your script is being run by Dash.

Dash does not expand {bin,usr,etc} like Bash does. I am guessing that you are using a distro that links /bin/sh to dash. You need to specify #!/bin/bash on the first line.
Ed

tvc457 05-03-2021 08:36 AM

Quote:

Originally Posted by voncloft (Post 6245807)
Hi when I try to use the following code in bash

mkdir{bin,usr,etc} I am left with a folder that is literally named: {bin,usr,etc} instead of 3 different folders.


Any ideas?

Why not try ?

mkdir "{bin,usr,etc}"

And let us know what Shell you use

NevemTeve 05-07-2021 01:43 AM

Brace expansion can be enabled/disabled with set command, e.g.:

Code:

$ set -B; printf "'%s'\n" {a1,b2,c3}
'a1'
'b2'
'c3'
$ set +B; printf "'%s'\n" {a1,b2,c3}
'{a1,b2,c3}'


tshikose 05-07-2021 07:05 AM

Quote:

Originally Posted by voncloft (Post 6245807)
Hi when I try to use the following code in bash

mkdir{bin,usr,etc} I am left with a folder that is literally named: {bin,usr,etc} instead of 3 different folders.


Any ideas?


Code:


mkdir ./{bin,usr,etc}


MadeInGermany 05-09-2021 01:07 PM

Quote:

mkdir ./{bin,usr,etc}
doesn't improve anything.
But the following:
Code:

mkdir bin usr etc

pan64 05-10-2021 12:58 AM

Quote:

Originally Posted by MadeInGermany (Post 6249513)
doesn't improve anything.
But the following:
Code:

mkdir bin usr etc

yes, this is the case where { and } are completely superfluous (excrescent).


All times are GMT -5. The time now is 09:46 PM.