result=`ps aux | grep “×××” |grep -v “×××”
start_time=$(echo $result | awk '{print $9}')
问题:发现输出是 start_time=“b”
检查发现:$result的值正常情况第7个($7)应该是”?“ 或者"pts/xx"等单个字符串,直接把ps aux | grep “×××” |grep -v “×××”在命令行执行也符合预期,可是我把start_time=$(echo $result | awk '{print $9}') 换成start_time=$(echo $result),$start_time的 $7 $8 $9是“! 1 b”,所以前面的start_time=“b”。猜想$result 中含特殊字符用echo输出时出错。
解决:start_time=$(echo “$result” | awk '{print $9}'),把$result加了引号就ok了。
转载于:https://www.cnblogs.com/ManMonth/p/3829265.html