It is currently Thu, 20 Jan 2022 04:17:57 GMT



 
Author Message
 How to negate command exit status in bash

        I am setting up a scripted situation so the following
scenario isn't quite as strange as it looks.  The grep -q command
is used at the shell prompt to look for a pass-phrase in a file.
If the pass-phrase is there, another command is executed.  The
command looks like

grep -q "some pass phrase" file_name && date

        The date prints if the file had the pass phrase.  That
works fine except that is the exact opposite of what I need in the
logic of the script.  The bash documentation says the ! character
can negate a condition.  I tried it both escaped and or quoted in
a couple of places that seemed right, but the shell either got
very confused judging by the error messages or it thought I was
trying to use the history.  I even tried grep -q -v "pass phrase" file
and it appears that the -v flag does not effect the exit status,
only the output.

        How do I test for the logical not of the exit status?
Remember that this command is typed at the shell prompt, not
within a shell script.

        Thank you.
--

Martin McCormick WB5AGZ  Stillwater, OK
OSU Center for Computing and Information Services Network Operations Group



 Tue, 07 Sep 2004 22:19:45 GMT   
 How to negate command exit status in bash
In article <a7fei1$jn...@hydrogen.cis.okstate.edu>,
Debian UserMartin McCormick <mar...@okstate.edu> wrote:

grep -q "some pass phrase" file_name || date
--
Conrad Sabatier <conr...@cox.net>



 Wed, 08 Sep 2004 02:23:53 GMT   
 How to negate command exit status in bash
In article <ZEKm8.53380$7B2.1459...@news1.east.cox.net>,
Conrad Sabatier  <conr...@cox.net> wrote:

        It worked like a charm.  I had convinced myself that this
was not the syntax to use, but that's what I get for thinking.:-)
--

Martin McCormick WB5AGZ  Stillwater, OK
OSU Center for Computing and Information Services Network Operations Group



 Sun, 12 Sep 2004 22:14:07 GMT   
 
   [ 3 post ] 

Similar Threads

1. Negating command exit status in bash

2. best practice for getting exit status of pipeline commands (bash, ksh, etc)

3. command exit status in bash

4. Test exit status of command prior to last command

5. Bash shell is always returning last exit status of the pipe

6. Obtaining the exit code (status) of command piped to tee

7. how to check exit status of a command within a C++ application

8. Exit Status of Command in rsh

9. route command exit status

10. How to get the exit status of a remote command executed via rsh


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software