[英]How do you indent when creating a multi line file from terminal?
So I need a command to make the output look like this: 所以我需要一个命令来使输出看起来像这样:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = ssh://git@github.com/user/address.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
I have tried the following, 我尝试了以下方法
printf "[core]\n repositoryformatversion = 0\n filemode = true\n bare = false\n logallrefupdates = true\n logallrefupdates = true\n[remote "origin"]\n url = ssh://git@github.com/user/address.git\n fetch = +refs/heads/*:refs/remotes/origin/*\n[branch "master"]\n remote = origin\n merge = refs/heads/master" > config
But it creates a file with these contents 但是它会创建一个包含这些内容的文件
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
logallrefupdates = true
[remote origin]
url = ssh://git@github.com/user/address.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch master]
remote = origin
merge = refs/heads/master
How can I make it wehre it outputs this in the format first stated? 如果以最初说明的格式输出此格式,我该如何设置?
Don't use printf
for this at all. 完全不要使用
printf
。 Just use a here document with cat
: 只需将此处文档与
cat
:
cat <<'EOF' > config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = ssh://git@github.com/user/address.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
EOF
Or, define a variable with the contents 或者,使用内容定义变量
config='
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = ssh://git@github.com/user/address.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
'
printf '%s\n' "$config" > config
在“ \\ n”之后,您可以使用“ \\ t”来创建标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.