LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2021, 05:46 AM   #1
voncloft
Member
 
Registered: Mar 2019
Posts: 54

Rep: Reputation: Disabled
Question 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?
 
Old 04-28-2021, 06:34 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
Works just fine for me:

Code:
$ cat test.sh
#!/bin/bash

mkdir {bin,usr,etc}

$ ./test.sh

$ ls
bin  etc  test.sh  usr
 
Old 04-28-2021, 06:41 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,490

Rep: Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532
would be nice to see what did you execute - exactly.
Is this your homework?
 
1 members found this post helpful.
Old 04-28-2021, 10:39 AM   #4
EdGr
Member
 
Registered: Dec 2010
Location: California, USA
Distribution: I run my own OS
Posts: 635

Rep: Reputation: 300Reputation: 300Reputation: 300Reputation: 300
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
 
2 members found this post helpful.
Old 05-03-2021, 08:36 AM   #5
tvc457
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Rep: Reputation: 0
Quote:
Originally Posted by voncloft View Post
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
 
Old 05-07-2021, 01:43 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,170
Blog Entries: 1

Rep: Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536
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}'
 
1 members found this post helpful.
Old 05-07-2021, 07:05 AM   #7
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 513

Rep: Reputation: 95
Quote:
Originally Posted by voncloft View Post
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}
 
Old 05-09-2021, 01:07 PM   #8
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,741

Rep: Reputation: 790Reputation: 790Reputation: 790Reputation: 790Reputation: 790Reputation: 790Reputation: 790
Quote:
mkdir ./{bin,usr,etc}
doesn't improve anything.
But the following:
Code:
mkdir bin usr etc
 
Old 05-10-2021, 12:58 AM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,490

Rep: Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532
Quote:
Originally Posted by MadeInGermany View Post
doesn't improve anything.
But the following:
Code:
mkdir bin usr etc
yes, this is the case where { and } are completely superfluous (excrescent).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: Cannot find 'ssh-keygen' in '/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin' venu.navat Linux - Software 3 03-08-2012 04:00 AM
echo $PATH = /home/g3rc4n/bin:/usr/local/bin:/usr/bin:/bin:/usr/games ? i_heart_pandas Linux - Software 7 09-18-2009 08:33 AM
FreeBSD 6.2, no /usr/src/tools and /usr/src/usr.bin, failed to build world. Mr_Shameless *BSD 4 05-16-2008 08:43 AM
path in services wrong for clamav updated frm 0.75 to 0.80 usr/bin vs usr/local/bin Emmanuel_uk Linux - Newbie 3 04-22-2005 01:02 AM
/usr/bin/X11/ and /usr/X11R6/bin/ the same? linuxtesting2 Linux - Newbie 2 11-16-2004 10:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration