confused about the output of if blocks

  Kiến thức lập trình

I have a shell script named wired-if.sh

#!/bin/bash
if $1;then echo ok;fi
if "$1";then echo ok;fi

then I run it without any parameters, the output is:

ok
./wierd-if.sh: line 3: : command not found

I am confused about the output, I think the 2 if blocks should all report errors, but the first is ok, the second report error,why?

then I ran the if blocks directly in the console

if ;then echo ok;fi
if "";then echo ok;fi

all report errors, why this happens?

LEAVE A COMMENT