Minwoo Minwoo - 5 months ago 20
Bash Question

How to hdfs shell script handle --config option

When I run

${HADOOP_HDFS_HOME}/bin/hdfs --config ${HADOOP_CONF_DIR} dfs -ls /
, How does hdfs shell script handle --config option?

The script does not compare
"COMMAND" = "--config"
, though COMMAND is
COMMAND=$1


hdfs shell script is here

COMMAND=$1

Answer

The option --config is handled in the hadoop-config.sh script, invoked by the hdfs-config.sh script, which is invoked in turn by hdfs:

#check to see if the conf dir is given as an optional argument
if [ $# -gt 1 ]
then
    if [ "--config" = "$1" ]
          then
              shift
              confdir=$1
              if [ ! -d "$confdir" ]; then
                echo "Error: Cannot find configuration directory: $confdir"
                exit 1
             fi
              shift
              HADOOP_CONF_DIR=$confdir
    fi
fi

You only had to dig into the script chain.

Comments