简体   繁体   English

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

[英]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.

相关问题 如何从终端更改文件的 MIME 类型? - How do you change the MIME type of a file from the terminal? 从管道在命令行上创建压缩包时,如何在压缩包中指定文件名? - How do you specify filenames within a zip when creating it on the command line from a pipe? 你如何防止输入在终端的新行上发送? - How do you prevent input from being sent on new line in terminal? 打开文件时如何在emacs中自动缩进? - How do I auto-indent in emacs when opening a file? 如何在打开matlab文件的同时从linux终端启动matlab? - How do you launch matlab from the linux terminal while also opening a matlab file? 如何将多行 bash 代码粘贴到终端并一次运行它? - How do I paste multi-line bash codes into terminal and run it all at once? 如何防止终端线覆盖自身? - How do I prevent the terminal line from overwriting itself? 如何在bash中间接分配变量以从Standard In,File和执行输出中获取多行数据 - How do I indirectly assign a variable in bash to take multi-line data from both Standard In, a File, and the output of execution 如何从多行文件中读取变量? - How to read in variables from multi-line file? 在没有termcap文件的情况下如何更改Fedora 20上的终端设置 - How do you change terminal settings on Fedora 20 with no termcap file only terminfo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM