You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-user@hadoop.apache.org by "Pundurs, Mark" <ma...@navteq.com> on 2012/01/13 16:49:37 UTC

-test -d return values in 0.20.2?

When using v0.20.2, the script command

echo "test result is >$( bin/hadoop dfs -test -d $FILEPATH )<"

gives the following output whether FILEPATH is a directory or a file:

test result is ><

Is this a known issue in 0.20.2? Or am I missing the point of -test -d? Or = what?

Mark Pundurs
Data Analyst - Traffic
Nokia Location & Commerce


The information contained in this communication may be CONFIDENTIAL and is intended only for the use of the recipient(s) named above.  If you are not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication, or any of its contents, is strictly prohibited.  If you have received this communication in error, please notify the sender and delete/destroy the original message and any copy of it from your computer or paper files.

RE: -test -d return values in 0.20.2?

Posted by "Pundurs, Mark" <ma...@navteq.com>.
So I was retrieving stdout rather than the return value. :( I've got this working now. Thanks, Harsh!

> From: Harsh J [mailto:harsh@cloudera.com]
> Sent: Friday, January 13, 2012 10:37 AM
>
> Hello Mark,
>
> The command is to be used by testing the return code observed:
>
> Option | Meaning | Success code | Failure code
>
> -d | directory test | 0 | 1
> -e | exists test | 0 | 1
> -z | empty file test | 0 | 1
>
> For non existent files or other errors, 255 is returned.
>
> In the shell, you can use $? to check return code of a command, and
> then run conditions on it as you'd like.
>
> Here's a sample way to use this (I have a dir 'examples' and a file
> 'README.txt'):
>
> ➜  ~HADOOP_HOME  hadoop dfs -test -d examples
> ➜  ~HADOOP_HOME  echo $?
> 0
> ➜  ~HADOOP_HOME  hadoop dfs -test -d README.txt
> ➜  ~HADOOP_HOME  echo $?
> 1
>
> On 13-Jan-2012, at 9:19 PM, Pundurs, Mark wrote:
>
> > When using v0.20.2, the script command
> >
> > echo "test result is >$( bin/hadoop dfs -test -d $FILEPATH )<"
> >
> > gives the following output whether FILEPATH is a directory or a file:
> >
> > test result is ><
> >
> > Is this a known issue in 0.20.2? Or am I missing the point of -test -
> d? Or = what?
> >
> > Mark Pundurs
> > Data Analyst - Traffic
> > Nokia Location & Commerce


The information contained in this communication may be CONFIDENTIAL and is intended only for the use of the recipient(s) named above.  If you are not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication, or any of its contents, is strictly prohibited.  If you have received this communication in error, please notify the sender and delete/destroy the original message and any copy of it from your computer or paper files.

Re: -test -d return values in 0.20.2?

Posted by Harsh J <ha...@cloudera.com>.
Hello Mark,

The command is to be used by testing the return code observed:

Option | Meaning | Success code | Failure code

-d | directory test | 0 | 1
-e | exists test | 0 | 1
-z | empty file test | 0 | 1

For non existent files or other errors, 255 is returned.

In the shell, you can use $? to check return code of a command, and then run conditions on it as you'd like.

Here's a sample way to use this (I have a dir 'examples' and a file 'README.txt'):

➜  ~HADOOP_HOME  hadoop dfs -test -d examples    
➜  ~HADOOP_HOME  echo $?
0
➜  ~HADOOP_HOME  hadoop dfs -test -d README.txt
➜  ~HADOOP_HOME  echo $?                       
1


On 13-Jan-2012, at 9:19 PM, Pundurs, Mark wrote:

> When using v0.20.2, the script command
> 
> echo "test result is >$( bin/hadoop dfs -test -d $FILEPATH )<"
> 
> gives the following output whether FILEPATH is a directory or a file:
> 
> test result is ><
> 
> Is this a known issue in 0.20.2? Or am I missing the point of -test -d? Or = what?
> 
> Mark Pundurs
> Data Analyst - Traffic
> Nokia Location & Commerce
> 
> 
> The information contained in this communication may be CONFIDENTIAL and is intended only for the use of the recipient(s) named above.  If you are not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication, or any of its contents, is strictly prohibited.  If you have received this communication in error, please notify the sender and delete/destroy the original message and any copy of it from your computer or paper files.