Binary Operator Expected Error When Checking for a File with a Full Path Name

pathname=$(cat $HOME/.rm.cfg) if [ ! -z $pathname/$1 ] 

.rm.cfg is a file containing the following directory

/ home / username / deleted1

$1 is the name of the file, for example. glass

why line if [ ! -z $pathname/$1 ] [ ! -z $pathname/$1 ] gives the expected binary operator error.

+8
unix
source share
2 answers

It looks like your $ pathname contains more than one word. There may be several lines in your .rm.cfg file, or perhaps the path includes spaces. Anyway, you end with

 if [ ! -z word word word/$1 ] 

which is useless. If you just expect one path and want to protect against a path containing spaces, change the if line to

 if [ ! -z "$pathname/$1" ] 
+15
source share

I came across the same error of the expected binary operator , where I get more than one word for some variable. When I used it as a mention below.

 if [ ! -z ${variable} ]; 

So, to fix this error, I changed it to:

 if [[ ! -z ${variable} ]]; 
+8
source share

All Articles