Hello,
what is wrong in selected in blue[/color blue] failed then selected in red[/color red] was executed?
I was expecting tht selected in red[/color red] will only be executed when [ ! -f $a ] is false /due to ()/.
Is a good solution adding "return 0" after the mkdir command? Or maybe other () sets would do the trick?
When doing it with if, only mkdir error is displayed (as expected):
what is wrong in selected in blue[/color blue] failed then selected in red[/color red] was executed?
I was expecting tht selected in red[/color red] will only be executed when [ ! -f $a ] is false /due to ()/.
Code:
$ a=tmp
$ [ ! -d $a ] && ( [ ! -f $a ] && ( echo "$a :: no such dir, so doing it";mkdir $a ) || echo "$a :: is a file, can't do dir" ) || echo "$a :: such dir already exists"
tmp :: no such dir, so doing it
$ [ ! -d $a ] && ( [ ! -f $a ] && ( echo "$a :: no such dir, so doing it";mkdir $a ) || echo "$a :: is a file, can't do dir" ) || echo "$a :: such dir already exists"
tmp :: such dir already exists
$ rmdir $a
$ touch $a
$ [ ! -d $a ] && ( [ ! -f $a ] && ( echo "$a :: no such dir, so doing it";mkdir $a ) || echo "$a :: is a file, can't do dir" ) || echo "$a :: such dir already exists"
tmp :: is a file, can't do dir
$ ls /test
ls: 0653-341 The file /test does not exist.
$ a=/test
$ [ ! -d $a ] && ( [ ! -f $a ] && [COLOR=blue]( echo "$a :: no such dir, so doing it";mkdir $a )[/color blue] || [COLOR=red]echo "$a :: is a file, can't do dir"[/color red] ) || echo "$a :: such dir already exists"
[COLOR=blue]/test :: no such dir, so doing it[/color blue]
mkdir: 0653-357 Cannot access directory /.
/: The file access permissions do not allow the specified action.
[COLOR=red]/test :: is a file, can't do dir[/color red]
$ su
root's Password:
$ mkdir /test
$ ls -ld /test
drwxr-xr-x 2 root system 256 Apr 03 14:41 /test
$ exit
$ [ ! -d $a ] && ( [ ! -f $a ] && ( echo "$a :: no such dir, so doing it";mkdir $a ) || echo "$a :: is a file, can't do dir" ) || echo "$a :: such dir already exists"
/test :: such dir already exists
$ su
root's Password:
$ rmdir /test
$ touch /test
$ exit
$ [ ! -d $a ] && ( [ ! -f $a ] && ( echo "$a :: no such dir, so doing it";mkdir $a ) || echo "$a :: is a file, can't do dir" ) || echo "$a :: such dir already exists"
/test :: is a file, can't do dir
$
Is a good solution adding "return 0" after the mkdir command? Or maybe other () sets would do the trick?
Code:
$ [ ! -d $a ] && ( [ ! -f $a ] && ( echo "$a :: no such dir, so doing it";mkdir $a 2>/dev/null ) || echo "$a :: is a file, can't do dir" ) || echo "$a :: such dir already exists"
/test :: no such dir, so doing it
/test :: is file, can't do dir
$ [ ! -d $a ] && ( [ ! -f $a ] && ( echo "$a :: no such dir, so doing it";mkdir $a 2>/dev/null;return 0 ) || echo "$a :: is a file, can't do dir" ) || echo "$a :: such dir already exists"
/test :: no such dir, so doing it
$ [ ! -d $a ] && ( [ ! -f $a ] && ( echo "$a :: no such dir, so doing it";mkdir $a 2>/dev/null;[ $? -ne 0 ] && echo mkdir failed;return 0 ) || echo "$a :: is a file, can't do dir" ) || echo "$a :: such dir a>
/test :: no such dir, so doing it
mkdir failed
$
When doing it with if, only mkdir error is displayed (as expected):
Code:
$ if [ ! -d $a ];then if [ ! -f $a ];then echo "$a :: no such dir, so doing it";mkdir $a;else echo "$a :: is file, can't do dir";fi;else echo "$a :: such dir already exists";fi
/test :: no such dir, so doing it
mkdir: 0653-357 Cannot access directory /.
/: The file access permissions do not allow the specified action.
$