Linux 一次创建一个完整的目录树
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17674406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a full directory tree at once
提问by James
I would like to create a complex directory structure in a bash script and was under the impression that the following would work:
我想在 bash 脚本中创建一个复杂的目录结构,并认为以下方法可行:
mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
Which would create:
这将创建:
tmpdir
________|______
| | |
branches tags trunk
|
sources
____|_____
| |
includes docs
However when I run my script I end up with:
但是,当我运行我的脚本时,我最终得到:
tmpdir
|
trunk
Is there a quick and easy way to do this or am I going to have to resort to
有没有一种快速简便的方法来做到这一点,或者我将不得不求助于
mkdir -p tmpdir/trunk/sources/includes
mkdir -p tmpdir/trunk/sources/docs
mkdir -p tmpdir/branches
mkdir -p tmpdir/tags
采纳答案by Grzegorz ?ur
Change shebang to
将shebang更改为
#!/bin/bash
to run the script with bash as it supports brace expansion.
使用 bash 运行脚本,因为它支持大括号扩展。
The problem is that you are using shell that does not support it. Your /bin/sh
does not point to /bin/bash
but to something like /bin/dash
.
问题是您使用的外壳不支持它。你的/bin/sh
不是指向/bin/bash
而是指向类似的东西/bin/dash
。