LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-13-2008, 02:58 PM   #1
akeenabawa
LQ Newbie
 
Registered: Jul 2008
Distribution: Fedora Core 2, Ubuntu 8
Posts: 13

Rep: Reputation: 0
Angry OR statement in Bash


Hi,
I have searched the web for help on this with no luck.
I have a Print-to-PDF script that reads the header for the USER and sends it to that users home directory. I am attempting to modify it to read two different lines.
I have:
Code:
then
  USER=`grep --text "@PJL LJOBINFO USERID =" $file`
  if ...
I need to add an OR after the USER= line, so that if it doesn't have that header but a different one, it still knows what it's looking for.
So it than reads:
Code:
then
  USER=`grep --text "@PJL LJOBINFO USERID =" $file`OR
  USER=`grep --text "NEW_HEADER=" $file`
  if ...
 
Old 11-13-2008, 03:22 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
In some programming languages we learn the if-then-else decision structure. If you are using a
bash shell script, the structure is if-do-done, or if-do-elseif-done.

So, one possible way to run your decision structure would be as follows:

if -e $file; # if the file exixts
do
USER=`grep --text "@PJL LJOBINFO USERID =" $file`
elseif
USER=`grep --text "NEW_HEADER=" $file`
done

or something similar.
 
Old 11-13-2008, 03:24 PM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
if the lines are mutually exclusive in a given file then there's no need for booleans per se:

VALUE=$(grep -e string1 -e string2)

and if you only wanted string2 if there is no occurence at all of string1:

VALUE=$(grep string1 || grep string2)

note $(...) offically replaced `...` a good few years ago
 
Old 11-14-2008, 10:17 AM   #4
akeenabawa
LQ Newbie
 
Registered: Jul 2008
Distribution: Fedora Core 2, Ubuntu 8
Posts: 13

Original Poster
Rep: Reputation: 0
Thank you both for your help. I incorporated the strings into the script and replaced `...` with $(...). I was also missing a piece somewhere else that the script needed to complete processing. So the script runs in the background now, and it picks up the files I send to the Print-to-PDF printer and turns them into PDF's.
Thanks again.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 07:00 AM
bash if statement jstu Programming 7 02-15-2008 08:48 PM
Bash if statement noir911 Programming 2 08-20-2006 06:43 AM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 06:20 PM
bash statement os2 Programming 2 03-20-2005 11:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration