巴什续行 [英] Bash continuation lines

查看:144
本文介绍了巴什续行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何使用bash续行?

我知道你可以做到这一点:

 回声延续\\
线
>续行

不过,如果你已经缩进code,它不工作这么好:

 回声延续\\
    线
>续行


解决方案

这是你可能想要的东西。

  $回声延续\\
> 线
续行

如果这造成两个参数呼应,你只需要一个,那么让我们来看看字符串连接。在bash中,将相邻连接两个字符串:

  $回声延续,线
continuationlines

所以,续行的没有缩进的就是要打破一个字符串的一种方法:

  $回声延续\\
> 线
continuationlines

但是,当使用缩进

  $回声延续\\
> 线
续行

您获得两个参数,因为这不再是一个串联。

如果您想横跨线,而缩进,但没有得到所有的这些空间一个字符串,一种方法可以尝试是沟续行和使用变量:

  $ a =延续
$ B =行
$回声$一个$ B
continuationlines

这将让你在其他变量的代价有干净缩进code。如果使局部变量,应该不会太差。

How do you use bash continuation lines?

I realize that you can do this:

echo "continuation \
lines"
>continuation lines

However, if you have indented code, it doesn't work out so well:

    echo "continuation \
    lines"
>continuation     lines

解决方案

This is what you may want

$       echo "continuation"\
>       "lines"
continuation lines

If this creates two arguments to echo and you only want one, then let's look at string concatenation. In bash, placing two strings next to each other concatenate:

$ echo "continuation""lines"
continuationlines

So a continuation line without an indent is one way to break up a string:

$ echo "continuation"\
> "lines"
continuationlines

But when an indent is used:

$       echo "continuation"\
>       "lines"
continuation lines

You get two arguments because this is no longer a concatenation.

If you would like a single string which crosses lines, while indenting but not getting all those spaces, one approach you can try is to ditch the continuation line and use variables:

$ a="continuation"
$ b="lines"
$ echo $a$b
continuationlines

This will allow you to have cleanly indented code at the expense of additional variables. If you make the variables local it should not be too bad.

这篇关于巴什续行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆