Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ksh or bash

Posted on 2011-09-20
4
291 Views
Last Modified: 2012-05-12
I have a small script like the below and it doesn't seem to like my synatx I have to change the expression to `cat $file | grep -c test105` -ge 10. But i would like to know why the below syntax doesn't work. Also the && doesn't seem to work

file="/path/to/the/file"
file2="/path/to/the/file2"
if [  `grep -c test105 $file` -ge 10  ]  &&  [  `grep -c test105 $file2` -ge 10 ]; then
echo "blah"
else
blah
fi
0
Comment
Question by:lolaferrari
  • 2
  • 2
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36569048
Hi,

all your variants should work just fine.

What exactly is the problem? Error message? Wrong output?

By the way, the syntax I'd recommend would be this:


if [[  $(grep -c test105 $file) -ge 10 &&  $(grep -c test105 $file2) -ge 10 ]]; then

wmp
0
 

Author Comment

by:lolaferrari
ID: 36569242
Thanks for that. Yeah, I thought my variants would work to but it seems to interpret the grep string as a value and the 10 as a value so you end up with

grep: test105: No such file or directory
grep: 10: No such file or directory
grep: test105: No such file or directory
grep: 10: No such file or directory


Would this just be the same ?

if [[  `grep -c test105 $file` -ge 10 &&  `grep -c test105 $file2` -ge 10 ]]; then
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 36569410
backticks  `  `  and $(   )  are functionally equivalent, but the latter is by far better readable!

Your error messages look just as if you had put the backticks around the whole expression ("grep" up to "10" instead of "grep" up to "$file", and as if you had written "grep c" instead of "grep -c".



0
 

Author Closing Comment

by:lolaferrari
ID: 36569498
many thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Audit HISTFILE for all users on AIX 9 145
AIX 6.1: need to grow single SAN disk rootvg, does this require a downtime? 11 56
Sed question 2 102
awk sed variable in file 3 73
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question