为了创建更易于管理的脚本,只将自己的输出写到一个位置本身(通过'exec > file'),是否有比下面更好的解决方案来组合stdout重定向+ zenity (在这种使用中依赖管道的stdout)?
parent.sh:
#!/bin/bash
exec >> /var/log/parent.out
( true; sh child.sh ) | zenity --progress --pulsate --auto-close --text='Executing child.sh')
[[ "$?" != "0" ]] && exit 1
...child.sh:
#!/bin/bash
exec >> /var/log/child.out
echo 'Now doing child.sh things..'
...当你做这样的事情时-
sh child.sh | zenity --progress --pulsate --auto-close --text='Executing child.sh'zenity从不从child.sh接收stdout,因为它是从child.sh内部重定向的。尽管这似乎有点麻烦,但使用包含“真”+执行child.sh的子subshell是否可以接受?还是有更好的方法来管理标准输出?
我知道在这个场景中使用“tee”是可以接受的,不过我不希望每次执行child.sh时都要写出would . in的日志文件位置。
发布于 2022-05-23 04:34:06
您的重定向exec > stdout.txt将导致错误。
$ exec > stdout.txt
$ echo hello
$ cat stdout.txt
cat: stdout.txt: input file is output file您需要一个中间文件描述符。
$ exec 3> stdout.txt
$ echo hello >&3
$ cat stdout.txt
hellohttps://stackoverflow.com/questions/71106437
复制相似问题