我有以下shell脚本,回声输出到日志和错误到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
Run Code Online (Sandbox Code Playgroud)
我希望将最后一个if条件的输出发送到std err但是,无法弄清楚该怎么做.
我怀疑你收到了一条错误信息.如果您发布它会有所帮助.但是,这可能会解决您的问题:
echo "UserInfo.SH FAILED copy to mtvst32" >&2
Run Code Online (Sandbox Code Playgroud)
删除空间和其中一个>.