Shell 脚本变量中未捕获计数
Count is not Captured in Shell Script Variable
我试图通过 运行 命令捕获活动进程的数量,并试图在 shell 脚本的变量中捕获结果,但不幸的是,没有捕获到任何东西。代码如下:
#!/bin/ksh
## Checking whether or not the Previous Build is Completed
count_build_status=`ps -ef | grep BDD_PreCheck.sh | grep -c FT_BGmgmt` | tee -a ${logFile}
echo "The Value of Count Build Status is $count_build_status"
if [[ "${count_build_status}" != "0" ]]
then
echo INFO - The previous build has not ended yet. Please Wait for some time or contact the Administrator | tee -a $logFile
exit 1;
fi
exit 0;
这里,ps -ef | grep BDD_PreCheck.sh | grep -c FT_BGmgmt
单独执行结果为0,但'count_build_status'中存储的值为null。
有人可以帮忙吗?
示例:将 cmd 行的输出捕获到变量并附加带有 tee 的日志文件:
var=`ps -ef | grep 0 | grep -c 1 | tee -a log`
echo $var
这里的问题是反引号,如果没有在反引号内完成发球,它不会为变量赋值。它应该包含在 logFile 的末尾,如下面的代码所示。
#!/bin/bash
logFile=log.txt
## Checking whether or not the Previous Build is Completed
count_build_status=`ps -ef | grep BDD_PreCheck.sh | grep -c FT_BGmgmt | tee -a ${logFile}`
echo "The Value of Count Build Status is $count_build_status"
if [[ "${count_build_status}" != "0" ]]
then
echo INFO - The previous build has not ended yet. Please Wait for some time or contact the Administrator | tee -a $logFile
exit 1;
fi
exit 0;
我试图通过 运行 命令捕获活动进程的数量,并试图在 shell 脚本的变量中捕获结果,但不幸的是,没有捕获到任何东西。代码如下:
#!/bin/ksh
## Checking whether or not the Previous Build is Completed
count_build_status=`ps -ef | grep BDD_PreCheck.sh | grep -c FT_BGmgmt` | tee -a ${logFile}
echo "The Value of Count Build Status is $count_build_status"
if [[ "${count_build_status}" != "0" ]]
then
echo INFO - The previous build has not ended yet. Please Wait for some time or contact the Administrator | tee -a $logFile
exit 1;
fi
exit 0;
这里,ps -ef | grep BDD_PreCheck.sh | grep -c FT_BGmgmt
单独执行结果为0,但'count_build_status'中存储的值为null。
有人可以帮忙吗?
示例:将 cmd 行的输出捕获到变量并附加带有 tee 的日志文件:
var=`ps -ef | grep 0 | grep -c 1 | tee -a log`
echo $var
这里的问题是反引号,如果没有在反引号内完成发球,它不会为变量赋值。它应该包含在 logFile 的末尾,如下面的代码所示。
#!/bin/bash
logFile=log.txt
## Checking whether or not the Previous Build is Completed
count_build_status=`ps -ef | grep BDD_PreCheck.sh | grep -c FT_BGmgmt | tee -a ${logFile}`
echo "The Value of Count Build Status is $count_build_status"
if [[ "${count_build_status}" != "0" ]]
then
echo INFO - The previous build has not ended yet. Please Wait for some time or contact the Administrator | tee -a $logFile
exit 1;
fi
exit 0;