相关疑难解决方法(0)

&& 和 || 之后的 bash 行续行在哪里 记录在案?

我在脚本中经常看到这个结构并自己使用它,但让我烦恼的是我似乎无法在文档中找到它。

例子:

[ -f file1 ] &&
[ -f file2 ] &&
echo "Both files exist." ||
echo "One or the other file doesn't exist."
Run Code Online (Sandbox Code Playgroud)

这也可以在换行符之前使用反斜杠来完成,如中所述man bash

If a \<newline> pair appears,  and  the  backslash  is  not
itself  quoted,  the \<newline> is treated as a line continuation (that
is, it is removed from the input stream and effectively ignored).
Run Code Online (Sandbox Code Playgroud)

例子:

[ -f file1 ] && \
[ -f file2 ] && \
echo "Both files exist." || \ …
Run Code Online (Sandbox Code Playgroud)

bash shell-script

34
推荐指数
1
解决办法
1万
查看次数

将长命令拆分为多行

我得到了一个 shell 脚本,在里面我得到了如下命令

#!/bin/sh
sh ../jboss/bin/standalone.sh --server-config=standalone-full.xml -Djboss.node.name=node1 -b 0.0.0.0 -bmanagement 0.0.0.0
Run Code Online (Sandbox Code Playgroud)

如何将线断成多条线以便更好地理解和管理

#!/bin/sh
sh ../jboss/bin/standalone.sh 
  --server-config=standalone-full.xml
  -Djboss.node.name=node1
  -b 0.0.0.0
  -bmanagement 0.0.0.0
Run Code Online (Sandbox Code Playgroud)

尝试在每行末尾使用反斜杠,但不起作用。

shell-script

3
推荐指数
2
解决办法
965
查看次数

标签 统计

shell-script ×2

bash ×1