我有以下shell脚本,echos输出到日志,错误输出到err_file。但是,我特别希望向stderr回应一些陈述。请帮忙
#!/bin/ksh
echo "paramPassed: $0 $#"
err_file="error_file.txt"
new_file="new_file.txt"
exec >> ${new_file}
#exec >> ${new_file} 2>${err_file}
#exec >> ${new_file} 2>&1
if [ $# -eq 1 ]; then
username=$1
fi
userInfo=$(paramInfo ${username} | awk -F: '{print $2}')
echo ${userInfo}
rcp ${err_file} mtvst32:/rcs/ver34/${err_file}
if [ $? -ne 0 ]; then
#This doesn't work. Need the following to go to console
echo "UserInfo.SH FAILED copy to mtvst32" >> &2;
fi
我希望将最后一个if条件的输出发送到std err但是,无法弄清楚该怎么做。
答案 0 :(得分:8)
我怀疑您收到错误消息。如果您发布它会有所帮助。但是,这可能会解决您的问题:
echo "UserInfo.SH FAILED copy to mtvst32" >&2
删除空格和其中一个>
。