方法一:
nohup sh test.sh >/dev/null 2>&1 &
示例如下:
#!/bin/bash
str=$"\n"
nohup sh test.sh >/dev/null 2>&1 &
sstr=$(echo -e $str)
echo $sstr
方法二:
wait 命令 有局限,建议使用方法一
nohup sh test.sh > test.out 2>&1 &
wait
本文介绍两种在Linux环境下运行后台进程的方法。第一种方法使用nohup命令将脚本重定向到/dev/null,忽略所有信号,确保进程在退出shell后仍能运行。第二种方法同样使用nohup,但将输出重定向到文件,便于查看进程状态。
方法一:
nohup sh test.sh >/dev/null 2>&1 &
示例如下:
#!/bin/bash
str=$"\n"
nohup sh test.sh >/dev/null 2>&1 &
sstr=$(echo -e $str)
echo $sstr
方法二:
wait 命令 有局限,建议使用方法一
nohup sh test.sh > test.out 2>&1 &
wait
9172
1285

被折叠的 条评论
为什么被折叠?