我正在尝试检查Hadoop中是否存在part-r文件。以下是样本。目录不存在。我试图捕获返回值,并将在if-else条件中使用它来显示消息并正确地继续。
dir_1="/user/cloudera/asdf"
dir_2=${dir_1}"/part*"
dir_3="/user/cloudera/asdf/part-r-00000"
dir_4="/user/cloudera/asdf/part-r"
echo "Check 1. " ${dir_1}
hadoop fs -test -e ${dir_1}
retval=$?
echo "1. status is " $retval
echo "Check 2. " ${dir_2}
hadoop fs -test -e ${dir_2}
retval=$?
echo "2. status is " $retval
echo "Check 3. " ${dir_3}
hadoop fs -test -e ${dir_3}
retval=$?
echo "3. status is " $retval
echo "Check 4. " ${dir_1}/part*
hadoop fs -test -e ${dir_1}/part*
retval=$?
echo "4. status is " $retval
echo "Check 5. "
hadoop fs -ls ${dir_2}
retval=$?
echo "5. Status is " $retval
输出
[cloudera@quickstart cc_poc]$ sh chk.sh
Check 1. /user/cloudera/asdf
1. status is 1
Check 2. /user/cloudera/asdf/part*
test: `/user/cloudera/asdf/part*': No such file or directory
2. status is 1
Check 3. /user/cloudera/asdf/part-r-00000
3. status is 1
Check 4. /user/cloudera/asdf/part*
test: `/user/cloudera/asdf/part*': No such file or directory
4. status is 1
Check 5.
ls: `/user/cloudera/asdf/part*': No such file or directory
5. Status is 1
如果我完全使用目录或文件名,则只返回返回状态。但如果我尝试使用*它会显示错误。
我的问题 1.为什么1&中没有显示错误消息3(目录或完整文件名) 2.是否可以抑制消息并仅为其他人返回状态。