小编Ale*_*rin的帖子

为单个管道命令设置 pipefail

我需要从非 BASH 脚本(即 PHP 脚本)执行许多管道 shell 命令,如下所示:

command1 | command2 | command3
Run Code Online (Sandbox Code Playgroud)

所以,如果 command1以非零退出代码失败,则每个其他命令也会失败。到目前为止,我想出的是:

set -o pipefail && command1 | command2 | command3
Run Code Online (Sandbox Code Playgroud)

但即使它从终端运行良好,如果从脚本执行它也会产生这个:

sh: 1: set: 非法选项 -o pipefail

linux shell command-line pipe

23
推荐指数
2
解决办法
2万
查看次数

将交换分区安装在 /dev/null 是什么意思?

我在swapon -s我正在使用的 VPS 上运行,发现有一个交换分区指向/dev/null.

# swapon -s
Filename        Type        Size    Used    Priority
/dev/null       partition   262144  0       -1
Run Code Online (Sandbox Code Playgroud)

这是否意味着没有任何实际的交换,交换出的任何东西都会丢失?这比根本没有任何交换更好/更糟吗?

的输出df -h

# df -h
Filesystem         Size  Used Avail Use% Mounted on
/dev/ploop63064p1   20G  1.3G   18G   7% /
none               128M  4.0K  128M   1% /dev
none               4.0K     0  4.0K   0% /sys/fs/cgroup
none                26M   40K   26M   1% /run
none               5.0M     0  5.0M   0% /run/lock
none               128M     0  128M   0% /run/shm
none               100M     0  100M   0% /run/user
Run Code Online (Sandbox Code Playgroud)

的输出cat …

linux swap virtual-memory

6
推荐指数
1
解决办法
2789
查看次数

标签 统计

linux ×2

command-line ×1

pipe ×1

shell ×1

swap ×1

virtual-memory ×1