问题遇到的现象和发生背景
hadoop 中 $(hdfs dfs -test -e file: ///home/hadoop/text.txt)
是判断有没有text.txt
这个文件,有的话输入echo $?
就是0,没有的话就是1。
那么可不可以把$(hdfs dfs -test -e file:///home/hadoop/text.txt)
理解为一个函数调用,并且这个函数会返回0或1
下面这段代码的作用是从HDFS中下载指定文件,如果本地文件与要下载的文件名称相同,则自动对下载的文件重命名
if $(hdfs dfs -test -e file:///home/hadoop/text.txt);
then $(hdfs dfs -copyToLocal text.txt ./text2.txt);
else $(hdfs dfs -copyToLocal text.txt ./text.txt);
fi
那么在这段shell命令中,如果有text.txt文件。那么$(hdfs dfs -test -e file:///home/hadoop/text.txt)
的值应该是0,那么会执行else语句,即不重命名。但此刻理应执行then语句,要重命名。
但在实际运行中,该段代码是没有问题的。我是哪里理解错了呢?