gpt4 book ai didi

linux - 从终端创建多行文件时如何缩进?

转载 作者:太空宇宙 更新时间:2023-11-04 09:15:50 24 4
gpt4 key购买 nike

所以我需要一个命令来使输出看起来像这样:

    [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 "[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

但是它创建了一个包含这些内容的文件

[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

我怎样才能让它以最初规定的格式输出?

最佳答案

根本不要为此使用 printf。只需将此处文档与 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

或者,用内容定义一个变量

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

关于linux - 从终端创建多行文件时如何缩进?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47942749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com