分类: LINUX
2018-01-25 14:34:17
Linux shell脚本中执行命令结果赋值给变量&&echo输出变量是否包含换行符的问题
echo $ret 和 echo "$ret" 区别:
如果是echo $ret,输出结果为一行,没有换行符
如果是echo "$ret",输出结果为多行,有换行符
# vim test.sh
#!/bin/sh
CORE_DIR=`pwd`
UI_DIR=$CORE_DIR/../tomcat8
target=$UI_DIR/webapps/ui/META-INF/MANIFEST.MF
newline=$'\n'
newline2=$newline$newline
ret="$newline============ ui Timestamp ===========$newline2"
if [ -e $target ]; then
ret+="$(cat $target | sed -n '/Timestamp/p' )"
else
ret+="File or directory not found."
fi
ret+="$newline2"
ret+="$newline============ core Timestamp ===========$newline2"
now=`date -I`
target_core=$CORE_DIR/logs/$now\.0\.log
if [ -e $target_core ]; then
ret+="$(grep Timestamp $target_core | sed -n '/Timestamp/p' | sed s'/\ \ \ \ //' | sed s'/"//g')"
else
ret+="core log file or directory not found."
fi
ret+=$newline
#echo $ret
echo "$ret"