Can you use logical operators in a case statement (bash)?
I'm pretty sure I already know the answer to this, but I want to make sure I'm not overlooking anything. I'm working on a log monitoring script and every 10 lines I want to display a summary of events. The thing is, there are a lot of possible events, that likely won't have happened, so I only want to include them in the summary if they've actually happened.
Right not I'm doing this through mulitple if statements, but that's incredibly ugly... I'm wondering if it's possible to do something like this (which does not work):
The only other solution I could come up with was to write a function along these lines:
Actually, now that I'm typing all of this out...I think that's how I'll go about it, but I'm still curious if you can use logic in case, or if it's just string matching.
In case anyone cares, here is my script thus far (it's still in progress, so the formatting may be off)
---------- Post updated 07-14-10 at 03:37 AM ---------- Previous update was 07-13-10 at 01:16 PM ----------
In case anyone cares...
This is the (more or less) finished project. It's still a bit wonky in places, and I'd appreciate any input on how I could have streamlined this, or made it more efficient
I'm having an issue with bash read input when using a case statement.
The script halts and doesn't read the input on the first loop. if I hit enter then the scripts starts to respond as expected. Need some help here.
defaultans=8hrs
read -e -i $defaultans -p "${bldwht}How long would you like... (5 Replies)
Hi Gurus,
I have the below BASH code which does not works for upper case alphabets except Z (upper case Z).
What may be the reason. Also escape sequences like \n, \t, \b, \033(1m \033(0m (For bold letter) are not working.
case $var in
)
echo "Lower case alphabet"
;;
... (7 Replies)
Hello All,
I am writing a script that is to be placed on multiple servers, and of course I've started
running into some compatibility issues for certain shell commands.
The code below worked just fine on most of my machines except for a couple.
Here I had 4 separate lines in my script that... (3 Replies)
I have the following bash script and it is not accepting the lines
"--"|"--""-")
"--""-"")
while
do
echo "Current Argument is ${1}"
case "$1" in
"--"|"--""-")
echo "Argument is ${1}"
shift # Skip ahead one to the next argument.
... (1 Reply)
Hi
I want to send a status mail if daily or weekly or monthly batch completed or aborted. Here is the code.
if && &&
||
Else if &&
&& ||
Else if &&
&& ||
then
mailx –s “Status Report” sumone@sumthing.com
else
print ”try again”
Plz suggest the changes. (3 Replies)
Hi,
shell is /bin/ksh
I am trying to do the following in my code.. but its showing me an error
if ] && ] ]]; then
echo "id is $ida and chk_dy is $chk_dy"
fi
the error I get is
syntax error at line 23 : `"$ida"' unexpected
I need to execute the... (2 Replies)
Hi All,
I have 2 variables. Result1 and Result2. I want to put a condition that if Both are True then echo "All True" Else Show Error.
Right now i am doing this and getting error.
if ;
then
echo "All True"
else
echo "Failed"
fi;
Error.
line 8: '
Solution: Looking for (2 Replies)
greetings,
I have a script that is taking input like this:
a
b
c
d
aa
bb
aaa
bbb
ccc
ddd
and formating it to be like this:
a b c d
aa bb
aaa bbb ccc ddd (4 Replies)
Hi,
I'm trying to write a routine to parse a file that contains data that will be read
into arrays. The file is composed of labels to identify data types and arbitrary
lines of data with the usual remarks and empty new lines as is common with
config files.
The initial pass is built as so:... (3 Replies)
Hi there, probably a really simple question to answer but i cant seem to find it
can I use a logical AND (&&) within a CASE statement ie (ps this is useless syntax but youll get the idea
case "$var1","$var2" in
'Billy' && 'Bobby')
... (1 Reply)