我有以下 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
我希望将最后一个 if 条件的输出发送到 std err 但是,不知道该怎么做。
最佳答案
我怀疑您收到了一条错误消息。如果您发布它会很有帮助。但是,这可能会解决您的问题:
echo "UserInfo.SH FAILED copy to mtvst32" >&2
删除空格和其中一个 >
。
关于echo - ksh 回显到特定语句的 stderr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4367960/