我想从另一个 bash 脚本启动一个 bash 脚本,但在它自己的进程组中启动它,就像从终端运行它一样。
有几个类似的问题,但我找不到与我的示例相匹配的答案。
拿这两个脚本
$ cat main.sh
#! /usr/bin/env bash
set -e
echo if this has been started in its own group the following will pass
ps -o ppid,pgid,command $$
ps -o pgid | grep $$
echo passed
$ cat wrapper.sh
#! /usr/bin/env bash
set -e
./main.sh
Run Code Online (Sandbox Code Playgroud)
当我main.sh
单独运行时,终端将其放入自己的组中:
$ ./main.sh
if this has been started in its own group the following will pass
PPID PGID COMMAND
20553 1276 bash ./main.sh
1276
1276
1276
passed
$ …
Run Code Online (Sandbox Code Playgroud) 我想观看一个文件,直到出现一些文字
我找到了这个答案:`tail -f`直到看到文字
但是当我在 ubuntu 上尝试时,它没有退出:
$ echo one > test.txt
$ echo two >> test.txt
$ echo three >> test.txt
$ echo four >> test.txt
$ cat test.txt | sed '/w/ q'
one
two
$
Run Code Online (Sandbox Code Playgroud)
按预期工作。但是当我尝试拖尾文件时
$ tail -f test.txt | sed '/w/ q'
one
two
Run Code Online (Sandbox Code Playgroud)
它永远不会退出。即使管道破裂,尾巴也不会停止。
有人知道tail
退出时如何sed
退出吗?
我正在尝试打印一些像这样输入的 unicode 代码
echo 0024 0025 | xargs -n1 echo # one code per line
| xargs printf '\u%s\n'
Run Code Online (Sandbox Code Playgroud)
希望得到这个
$
%
Run Code Online (Sandbox Code Playgroud)
但这就是我得到的
printf: missing hexadecimal number in escape
Run Code Online (Sandbox Code Playgroud)
经过一些试验和错误,我实际上有两个较小的问题,一种是有道理的,另一种似乎完全是个谜。
问题1:
echo 0024 0025 | xargs -n1 echo # one code per line
| xargs printf '\u%s\n'
Run Code Online (Sandbox Code Playgroud)
给我这个
-bash: printf: missing unicode digit for \u
\u0024
-bash: printf: missing unicode digit for \u
\u0025
Run Code Online (Sandbox Code Playgroud)
问题2:
$
%
Run Code Online (Sandbox Code Playgroud)
(使用>
for$
以便您可以$
在输出中看到)
出于某种原因,有些字符适用于 exe 版本,但有些字符即使使用内置 printf 也适用。
所以这里有一个解决方法,如果不是问题#2,它会起作用(但可能比我原来的想法慢很多) …