LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 06-01-2011, 03:07 AM   #16
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,590

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233

That's looking more like it, but I guess you don't really want to comment out those last two lines :-)

Evo2.

---------- Post added 2011-06-01 at 16:07 ----------

That's looking more like it, but I guess you don't really want to comment out those last two lines :-)

Evo2.
 
Old 06-01-2011, 03:23 AM   #17
manyrootsofallevil
Member
 
Registered: Dec 2010
Distribution: Red Hat, Kubuntu
Posts: 130

Rep: Reputation: 14
Quote:
Originally Posted by gremlin007 View Post
so hang on is this wrong ?
Code:
#!/bin/bash
# rpm -q package_name
and should it be like this

Code:
#!/bin/bash
# rpm -q package_name
# var1=$0
# rpm -q --queryformat '%{description}' $var1
$0 references the name of the script as corp769 and evo2 have both pointed out. So you need $1.

You may as well have this line only
Code:
rpm -q --queryformat '%{description}' $1
Of course you'll have an error message if the script has no input but ..

Edit:

oops, it took me too long to post this.

Last edited by manyrootsofallevil; 06-01-2011 at 03:26 AM.
 
1 members found this post helpful.
Old 06-01-2011, 03:23 AM   #18
gremlin007
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
my code

my code so far :

Code:
#!/bin/bash
rpm -q readahead
var1=$1
rpm -q --queryformat '%{description}' $1
now next bit

Displays an error message if the user does not specify an argument and terminates

any specific/ similar example ? you can provide hep me do this

Last edited by gremlin007; 06-01-2011 at 03:26 AM.
 
Old 06-01-2011, 03:26 AM   #19
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,590

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
If no argument is supplied "$1" will be "". So, I think you should try to find out how to use 'if' statements to test $1, 'echo' to report an error and 'exit' to terminate the script. Google is your friend, as are the links you were given earlier.

Evo2.
 
Old 06-01-2011, 03:28 AM   #20
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,590

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
One more, thing: have you tested this script that you are writing?

Evo2.
 
Old 06-01-2011, 03:52 AM   #21
gremlin007
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
so


Displays an error message if the user does not specify an argument and terminates


Code:
#! /bin/bash
T1= "openssh"
E1= "error "
rpm -q $T1
if
	[ "$T1" = 2<1 ]
then 
echo $E1
does this make sense
 
Old 06-01-2011, 03:57 AM   #22
manyrootsofallevil
Member
 
Registered: Dec 2010
Distribution: Red Hat, Kubuntu
Posts: 130

Rep: Reputation: 14
Have a look at this tutorial http://www.codecoffee.com/tipsforlin...cles2/043.html

When is the homework due?
 
1 members found this post helpful.
Old 06-01-2011, 04:04 AM   #23
manyrootsofallevil
Member
 
Registered: Dec 2010
Distribution: Red Hat, Kubuntu
Posts: 130

Rep: Reputation: 14
Quote:
Originally Posted by gremlin007 View Post

Displays an error message if the user does not specify an argument and terminates


Code:
#! /bin/bash
T1= "openssh"
E1= "error "
rpm -q $T1
if
	[ "$T1" = 2<1 ]
then 
echo $E1
does this make sense
It makes sense if you test it and it does what you expect it to do, otherwise it doesn't.

Everybody will have different ways of writing a script/program that achieves the same task. Some ways are more efficient, more elegant, run faster but you'll get there with time and practice.
 
Old 06-01-2011, 04:07 AM   #24
gremlin007
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
Home work

i'm trying to get ahead on this question
its an example the lecturer posted for our next prac

only he doesn't explain our pracs to well so i thought i'd get a heads up
 
Old 06-01-2011, 01:40 PM   #25
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 1,773

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by gremlin007 View Post
so

Code:
#!/bin/bash
# rpm -q package_name
# var1=$1
# rpm -q --queryformat '%{description}' $var1
Lines starting with '#' are comments. They aren't executed by bash.
 
  


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
bash shell scripting help! computergeek7 Programming 2 04-27-2010 11:35 AM
Bash Shell scripting help! computergeek7 Programming 2 03-01-2010 06:55 AM
My first bash at shell scripting (sorry...) Daws Linux - Newbie 5 03-21-2007 07:20 PM
some bash shell scripting eltongeoff Linux - Newbie 2 10-22-2003 02:10 PM
Bash Shell Scripting Help Tangerine Programming 6 05-06-2003 03:10 PM


All times are GMT -5. The time now is 08:09 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration