Corona688's grep -q solution is the best, but so you understand how things work I'll try and explain how one gets to it.
1. call grep, and throw away it's output and then examine return status:
Grep (and most unix commands) set exit status ($?) to zero on sucess (ie expresion matches), and non-zero for failure (expression not found or other errors, eg could not open file)
2. Grep supports a -q option (be quiet and just set exit status), so we can simplify to:
3. if runs command and executes block when command result is zero ( [ is just a shortcut for the test command). So we can use if to directly test the grep result:
This User Gave Thanks to Chubler_XL For This Post:
I keep getting an error at line 21, it doesn't like my if statement. Previously I have tried using (( )), but still get errors. The current error is that server_busy is not found. This is the script:
#! /bin/ksh
server_busy="na"
for file in $1 $2 $3 $4 $5 $6
do
echo " ${file}\t\c"
... (1 Reply)
I need an IF statement that will compare the contents of the variable CX with the actual string "CP". ie. If the contents of $CX are NOT equal to the actual string "CP" then blah blah blah.
I have tried a number of things including the following.......
if ]; then
if ]; then
if ];... (2 Replies)
hi all. i just have a very small problem. i have a menu of 7 choices. i want an if statement so that if the user chooses anything except inside the 1 to 7 range, i can handle the error for it.
i tried this:
if ]
then
.......
fi
(but it dont work)
...any suggestions?
... (4 Replies)
The problem I am having here is that only the 1st option is executed, no matter if I pick yes or no. What am I doing wrong? How can I get this working right without resorting to a case statement?
echo "This is the max size your lvol can be:"
echo $MAXSIZE
echo
echo Do you want to max out... (2 Replies)
Hi I have a bash script like this
if
then
echo "A"
else
echo "B"
fi
$1 is something like 02350 (there is always a trailing '0')
and I would like to have an if based on the value of the digits after the 0.
Can anybody help?
Thanks,
Sarah (3 Replies)
Could someone help me out with this if statement? It's supposed to get a person's website, but it isn't working when I run it.
website=""
echo "Would you like to enter a website? Enter Yes/No"
read choice
if
then
while
do
echo "Please enter a website:";
read... (4 Replies)
Hi,
Here is a big head scratcher for me....
I'm creating a loop with while reading lines from a file called example.txt:
#!/bin/sh
while read line
do
some command > another file ----- output to another file
done < example.txt
I would like that another file to be unique for every... (5 Replies)
echo "Enter the variable: " "
read var1
echo " "
for i in ib eb atm
do
if ; then
mv properties environment.properties
break
else
echo "No changes to $var1 "
fi
done
When i run and enter the eb it's not working.Any suggestions please.. (7 Replies)
Hi All,
I am writing an if statement to check multiple conditions, but when I try to execute the script it is breaking at the point of if statement by showing the issue below.
Code I am using is given below.
if -a ]
then
....
else
...
fi
I am not understanding... (3 Replies)
Discussion started by: ginrkf
3 Replies
LEARN ABOUT V7
zgrep
ZGREP(1) General Commands Manual ZGREP(1)NAME
zgrep - search possibly compressed files for a regular expression
SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename...
DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code:
(-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the
standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep.
If the GREP environment variable is set, zgrep uses it as the grep program to be invoked.
EXIT CODE
2 - An option that is not supported was specified.
AUTHOR
Charles Levert (charles@comm.polymtl.ca)
SEE ALSO grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1)ZGREP(1)