Skip to main content
added 171 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

It's meaningless.

That's the way ksh93 handle if there're too many arguments for an unary operator and the unary operator start with -, then the second one will be pick as the argument and the rest will be ignored:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ ksh -c '[ -e a.out foo a ] && echo yes' yes 

(Except when the second argument is -a/-o, it won't be ignored)

Checking the source of ksh93 test confirm that behavior.

Also doing strace:

$ { strace -p "$$" & sleep 1; [ -f a.out -size +0 ]; kill "$!"; } [1] 18467 Process 18455 attached restart_syscall(<... resuming interrupted call ...>) = 0 stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 stat("a.out", {st_mode=S_IFREG|0755, st_size=8320, ...}) = 0 kill(18467, SIGTERMProcess 18455 detached <detached ...> 

Other Bourne-like shellshells will report the error when too many arguments provide to unary operatorwith this case. The behavior is unspecified by POSIX.


If you want to check whether a file exist and have size greater than 0, then standard shells have -s test operator:

[ -s file ] && echo 'file exist and size greater than 0' 

ksh88 also behave the same. With my Solaris 10 VM:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ strings /usr/bin/ksh | grep -i version @(#)Version M-11/16/88i 

Pre-POSIX shells also behave like that, include Bourne shell in Solaris 10, the heirloom Bourne shell, Schily osh and Schily sh.

It's meaningless.

That's the way ksh93 handle if there're too many arguments for an unary operator and the unary operator start with -, then the second one will be pick as the argument and the rest will be ignored:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ ksh -c '[ -e a.out foo a ] && echo yes' yes 

(Except when the second argument is -a/-o, it won't be ignored)

Checking the source of test confirm that behavior.

Also doing strace:

$ { strace -p "$$" & sleep 1; [ -f a.out -size +0 ]; kill "$!"; } [1] 18467 Process 18455 attached restart_syscall(<... resuming interrupted call ...>) = 0 stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 stat("a.out", {st_mode=S_IFREG|0755, st_size=8320, ...}) = 0 kill(18467, SIGTERMProcess 18455 detached <detached ...> 

Other Bourne-like shell will report the error when too many arguments provide to unary operator.


If you want to check whether a file exist and have size greater than 0, then standard shells have -s test operator:

[ -s file ] && echo 'file exist and size greater than 0' 

ksh88 also behave the same. With my Solaris 10 VM:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ strings /usr/bin/ksh | grep -i version @(#)Version M-11/16/88i 

Pre-POSIX shells also behave like that, include Bourne shell in Solaris 10, the heirloom Bourne shell, Schily osh and Schily sh.

It's meaningless.

That's the way ksh93 handle if there're too many arguments for an unary operator and the unary operator start with -, then the second one will be pick as the argument and the rest will be ignored:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ ksh -c '[ -e a.out foo a ] && echo yes' yes 

(Except when the second argument is -a/-o, it won't be ignored)

Checking the source of ksh93 test confirm that behavior.

Also doing strace:

$ { strace -p "$$" & sleep 1; [ -f a.out -size +0 ]; kill "$!"; } [1] 18467 Process 18455 attached restart_syscall(<... resuming interrupted call ...>) = 0 stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 stat("a.out", {st_mode=S_IFREG|0755, st_size=8320, ...}) = 0 kill(18467, SIGTERMProcess 18455 detached <detached ...> 

Other Bourne-like shells will report the error with this case. The behavior is unspecified by POSIX.


If you want to check whether a file exist and have size greater than 0, then standard shells have -s test operator:

[ -s file ] && echo 'file exist and size greater than 0' 

ksh88 also behave the same. With my Solaris 10 VM:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ strings /usr/bin/ksh | grep -i version @(#)Version M-11/16/88i 

Pre-POSIX shells also behave like that, include Bourne shell in Solaris 10, the heirloom Bourne shell, Schily osh and Schily sh.

added 171 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

It's meaningless.

That's probably a bug withthe way ksh93, handle if there're too many arguments for an unary operator and the unary operator start with -, then the second one will be pick as the argument and the rest will be ignored:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ ksh -c '[ -e a.out foo a ] && echo yes' yes 

(Except when the second argument is -a/-o, it won't be ignored)

Checking the source of test confirm that behavior.

Also doing strace:

$ { strace -p "$$" & sleep 1; [ -f a.out -size +0 ]; kill "$!"; } [1] 18467 Process 18455 attached restart_syscall(<... resuming interrupted call ...>) = 0 stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 stat("a.out", {st_mode=S_IFREG|0755, st_size=8320, ...}) = 0 kill(18467, SIGTERMProcess 18455 detached <detached ...> 

ifOther Bourne-like shell will report the error when too many arguments provide to unary operator.


If you want to check whether a file exist and have size greater than 0, then standard shells have -s test operator:

[ -s file ] && echo 'file exist and size greater than 0' 

ksh88 seems to havealso behave the same bug. With my Solaris 10 VM:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ strings /usr/bin/ksh | grep -i version @(#)Version M-11/16/88i 

Pre-POSIX shells also behave like that, include Bourne shell in Solaris 10, the heirloom Bourne shell, Schily osh and Schily sh.

It's meaningless.

That's probably a bug with ksh93, if there're too many arguments for an unary operator and the unary operator start with -, then the second one will be pick as the argument and the rest will be ignored:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ ksh -c '[ -e a.out foo a ] && echo yes' yes 

Checking the source of test confirm that behavior.

Also doing strace:

$ { strace -p "$$" & sleep 1; [ -f a.out -size +0 ]; kill "$!"; } [1] 18467 Process 18455 attached restart_syscall(<... resuming interrupted call ...>) = 0 stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 stat("a.out", {st_mode=S_IFREG|0755, st_size=8320, ...}) = 0 kill(18467, SIGTERMProcess 18455 detached <detached ...> 

if you want to check whether a file exist and have size greater than 0, then standard shells have -s test operator:

[ -s file ] && echo 'file exist and size greater than 0' 

ksh88 seems to have the same bug. With my Solaris 10 VM:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ strings /usr/bin/ksh | grep -i version @(#)Version M-11/16/88i 

Pre-POSIX shells also behave like that, include Bourne shell in Solaris 10, the heirloom Bourne shell, Schily osh and Schily sh.

It's meaningless.

That's the way ksh93 handle if there're too many arguments for an unary operator and the unary operator start with -, then the second one will be pick as the argument and the rest will be ignored:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ ksh -c '[ -e a.out foo a ] && echo yes' yes 

(Except when the second argument is -a/-o, it won't be ignored)

Checking the source of test confirm that behavior.

Also doing strace:

$ { strace -p "$$" & sleep 1; [ -f a.out -size +0 ]; kill "$!"; } [1] 18467 Process 18455 attached restart_syscall(<... resuming interrupted call ...>) = 0 stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 stat("a.out", {st_mode=S_IFREG|0755, st_size=8320, ...}) = 0 kill(18467, SIGTERMProcess 18455 detached <detached ...> 

Other Bourne-like shell will report the error when too many arguments provide to unary operator.


If you want to check whether a file exist and have size greater than 0, then standard shells have -s test operator:

[ -s file ] && echo 'file exist and size greater than 0' 

ksh88 also behave the same. With my Solaris 10 VM:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ strings /usr/bin/ksh | grep -i version @(#)Version M-11/16/88i 

Pre-POSIX shells also behave like that, include Bourne shell in Solaris 10, the heirloom Bourne shell, Schily osh and Schily sh.

added 4 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

It's meaningless.

That's probably a bug with ksh93, if there're too many arguments for aan unary operator and the unary operator start with -, then the second one will be pick as the argument and the rest will be ignored:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ ksh -c '[ -e a.out foo a ] && echo yes' yes 

Checking the source of test confirm that behavior.

Also doing strace:

$ { strace -p "$$" & sleep 1; [ -f a.out -size +0 ]; kill "$!"; } [1] 18467 Process 18455 attached restart_syscall(<... resuming interrupted call ...>) = 0 stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 stat("a.out", {st_mode=S_IFREG|0755, st_size=8320, ...}) = 0 kill(18467, SIGTERMProcess 18455 detached <detached ...> 

if you want to check whether a file exist and have size greater than 0, then standard shells have -s test operator:

[ -s file ] && echo 'file exist and size greater than 0' 

ksh88 seems to have the same bug. With my Solaris 10 VM:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ strings /usr/bin/ksh | grep -i version @(#)Version M-11/16/88i 

Pre-POSIX shells also behave like that, include Bourne shell in Solaris 10, the heirloom Bourne shell, Schily osh and Schily sh.

It's meaningless.

That's probably a bug with ksh93, if there're too many arguments for a unary operator and the unary operator start with -, then the second one will pick as the argument and the rest will be ignored:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ ksh -c '[ -e a.out foo a ] && echo yes' yes 

Checking the source of test confirm that behavior.

Also doing strace:

$ { strace -p "$$" & sleep 1; [ -f a.out -size +0 ]; kill "$!"; } [1] 18467 Process 18455 attached restart_syscall(<... resuming interrupted call ...>) = 0 stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 stat("a.out", {st_mode=S_IFREG|0755, st_size=8320, ...}) = 0 kill(18467, SIGTERMProcess 18455 detached <detached ...> 

if you want to check whether a file exist and have size greater than 0, then standard shells have -s test operator:

[ -s file ] && echo 'file exist and size greater than 0' 

ksh88 seems to have the same bug. With my Solaris 10 VM:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ strings /usr/bin/ksh | grep -i version @(#)Version M-11/16/88i 

Pre-POSIX shells also behave like that, include Bourne shell in Solaris 10, the heirloom Bourne shell, Schily osh and Schily sh.

It's meaningless.

That's probably a bug with ksh93, if there're too many arguments for an unary operator and the unary operator start with -, then the second one will be pick as the argument and the rest will be ignored:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ ksh -c '[ -e a.out foo a ] && echo yes' yes 

Checking the source of test confirm that behavior.

Also doing strace:

$ { strace -p "$$" & sleep 1; [ -f a.out -size +0 ]; kill "$!"; } [1] 18467 Process 18455 attached restart_syscall(<... resuming interrupted call ...>) = 0 stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 stat("a.out", {st_mode=S_IFREG|0755, st_size=8320, ...}) = 0 kill(18467, SIGTERMProcess 18455 detached <detached ...> 

if you want to check whether a file exist and have size greater than 0, then standard shells have -s test operator:

[ -s file ] && echo 'file exist and size greater than 0' 

ksh88 seems to have the same bug. With my Solaris 10 VM:

$ ksh -c '[ -f a.out foo bar ] && echo yes' yes $ strings /usr/bin/ksh | grep -i version @(#)Version M-11/16/88i 

Pre-POSIX shells also behave like that, include Bourne shell in Solaris 10, the heirloom Bourne shell, Schily osh and Schily sh.

added 139 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420
Loading
added 22 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420
Loading
added 203 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420
Loading
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420
Loading