bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug-bash Digest, Vol 215, Issue 9


From: Robert Elz
Subject: Re: bug-bash Digest, Vol 215, Issue 9
Date: Mon, 12 Oct 2020 01:49:47 +0700

    Date:        Sun, 11 Oct 2020 16:26:58 +0700
    From:        Budi <budikusasi@gmail.com>
    Message-ID:  
<CAH0GyZACPb2dtZkqkNwZZLLH4RgNRVrSv31_aYxg3hwCdq_q0Q@mail.gmail.com>

  | set -n not work as its supposed job to check validity of a command

That is not what it does.   When -n is set, commands are not executed,
simply parsed.

  | $ set -n 'echo HI' &&echo Y
  | Y

What that does is turn on the -n option, and also set $1 to 'echo HI'
which is not what you intended I think.   Since the set command succeeds
the "echo Y" then runs.

It isn't really clear anywhere when -n (when set) takes effect (it
is usually only ever used on the command line as in

        bash -n script

to have the script parsed, but not executed.   That's what the
"check validity" is about - and note that it only checks for
syntax errors, so something like

  | $ set -n 'eco HI' &&echo Y

even if it was done properly, couldn't work, as the shell does not
try to execute the 'eco' command when -n is in effect (assuming this
was rewritten so that an attempt would be made) so it never discovers
that there is no such command.

  | won't do the check, how to solve ?

Depends on what you're really trying to do, which cannot possibly be
to discover whether "eco" is a known command or not, or at least I
hope not.

kre




reply via email to

[Prev in Thread] Current Thread [Next in Thread]