2

I have this simple script:

#!/bin/bash
echo ${HADOOP_HOME}
$(hadoop fs -ls)

The output is:

/opt/hadoop-0.20.2-cdh3u2
./hello.sh: line 3: Found: command not found

So bash definitely sees HADOOP_HOME. I've set it in ~/.profile and added path to bin folder:

export HADOOP_HOME="/opt/hadoop-0.20.2-cdh3u2"
export PATH=$PATH:$HADOOP_HOME/bin

If I simply invoke command in console everything works but inside a script it doesn't. What am I doing wrong?

1 Answer 1

2

It's not the problem with echo ${HADOOP_HOME} command.The one which causes the error is $(hadoop fs -ls)

You have to give the 3rd line in that script as echo $(hadoop fs -ls). So the script will look like,

#!/bin/bash
echo ${HADOOP_HOME}
echo $(hadoop fs -ls)

If you give the command like this $(hadoop fs -ls), bash parses it and find it's value. And the founded value is again parsed by bash.

Example:

$ var=4
$ $var
4: command not found
$ echo $var
4

IMO, the value or the output of the command hadoop fs -ls is Found, this string found was again parsed by bash when you give the command like this $(hadoop fs -ls). So that the below error message displayed while executing the script hello.sh,

./hello.sh: line 3: Found: command not found
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .