Sponsored Content
Top Forums Shell Programming and Scripting Simple program but problem-pls Help Post 302212618 by zaxxon on Tuesday 8th of July 2008 03:02:30 AM
Old 07-08-2008
Btw: There is no need to have semicolons at the end of variable declaration in bash and there is a [ C O D E ] tag to put code into a box so you don't have to mark it red Smilie

Just as namishtiwari wrote, or define the values as integer and you can got with arithmetic signs (else it will think you might want to redirect an output):
Code:
#!/bin/sh
typeset -i value1=90
typeset -i value2=70
if [ $value1 > $value2 ]; then
   echo "$value1 is normal"
else
   echo "$value2 is abnormal"
fi

 

10 More Discussions You Might Find Interesting

1. Programming

QUESTION...simple program?

I am new to the unix/linux environment. AND........ I need to create a mini shell..that displays prompt (i.e., READY:$), accepts a command from std-in, and prints the command and any parameters passed to it. HELP!!!! (8 Replies)
Discussion started by: jj1814
8 Replies

2. Shell Programming and Scripting

HELP me PLS... Simple Scripting!

this is my script.... SQL> select * from dba_profiles 2 where resource_name in ('FAILED_LOGIN_ATTEMPTS','PASSWORD_LOCK_TIME') 3 order by profile; and this is the output... PROFILE RESOURCE_NAME RESOURCE... (2 Replies)
Discussion started by: liezer
2 Replies

3. Programming

a simple chat program

any suggestions on how i could create a simple chat program between two terminals using pipes? thanks (1 Reply)
Discussion started by: kelogs1347
1 Replies

4. Shell Programming and Scripting

Problem.. can someone pls help..

Hi All, My file contains data like below. Key ~PILCSZY First Name Szymon Surname Pilch User Code Group SCO-PL User Group Description SCO - Poland Key ... (2 Replies)
Discussion started by: harshakusam
2 Replies

5. Programming

Xlib simple program.

I don't know if it is right to ask you this. Can someone help me write a simple Xlib program,with button on it,and all that button do is switch 2 messages. I have tried and tried,but never get past Hello World. Can someone help me please? ---------- Post updated at 10:17 PM ---------- Previous... (2 Replies)
Discussion started by: megane16v
2 Replies

6. Shell Programming and Scripting

simple program help required

The circumfrence of a circle is #!/usr/bin/perl print 2 * 3.141592654 * 12.50 \n"; # pi= 3.141592654 # r= 12.50 I need a simple program showing me all the steps..to modify the above to prompt for and accept a radius from the person running the... (3 Replies)
Discussion started by: Q2wert
3 Replies

7. Shell Programming and Scripting

Shell program help pls

first queestion if what does "-s" mean? second seqx -n 10000000 -c 10 < $seqfile >$temp seqx? -n? -c? what do these mean? third if && ! cmp -s $missing $temp explain these codes ty (2 Replies)
Discussion started by: imtheone
2 Replies

8. Shell Programming and Scripting

Help with simple program. (beginner)

Hey all, Writing a program that searches for a username and if they are online creates a 'beep' and sends the username and date to a log file. the error i am getting is: paul.obrien16@aisling:~/os$ bash checklogin : command not found Enter username paul.obrien16 ': not a valid... (2 Replies)
Discussion started by: sexyladywall
2 Replies

9. UNIX for Dummies Questions & Answers

Help with creating a simple program!!

i am new to shell scripting!! i am making this program in bourne shell, that asks the user to input "Hello (their name)" or "question (their name)", any other input, "ERROR" will be outputted. if they input "Hello (name)", i want to out saying Hello (name) but if they input "question (name)", i... (4 Replies)
Discussion started by: bshell_1214
4 Replies

10. Programming

A simple C program query ...

Given the following code inside the function ext3_write_super(): (It's there in Linux kernel 2.6.27.59) static void ext3_write_super (struct super_block * sb) { if (mutex_trylock(&sb->s_lock) != 0) BUG(); sb->s_dirt = 0; } The conditional test at if... (2 Replies)
Discussion started by: Praveen_218
2 Replies
Jifty::DBI(3pm) 					User Contributed Perl Documentation					   Jifty::DBI(3pm)

NAME
Jifty::DBI - An object-relational persistence framework DESCRIPTION
Jifty::DBI deals with databases, so that you don't have to. This module provides an object-oriented mechanism for retrieving and updating data in a DBI-accessible database. This module is the direct descendant of DBIx::SearchBuilder. If you're familiar with SearchBuilder, Jifty::DBI should be quite familiar to you. Purpose Jifty::DBI::Record abstracts the agony of writing the common and generally simple SQL statements needed to serialize and deserialize an object to the database. In a traditional system, you would define various methods on your object 'create', 'read', 'update', and 'delete' being the most common. In each method you would have a SQL statement like: select * from table where value='blah'; If you wanted to control what data a user could modify, you would have to do some special magic to make accessors do the right thing. Etc. The problem with this approach is that in a majority of the cases, the SQL is incredibly simple and the code from one method/object to the next was basically the same. <trumpets> Enter, Jifty::DBI::Record. With ::Record, you can in the simple case, remove all of that code and replace it by defining two methods and inheriting some code. It's pretty simple and incredibly powerful. For more complex cases, you can do more complicated things by overriding certain methods. Let's stick with the simple case for now. An Annotated Example The example code below makes the following assumptions: o The database is 'postgres', o The host is 'reason', o The login name is 'mhat', o The database is called 'example', o The table is called 'simple', o The table looks like so: id integer not NULL, primary_key(id), foo varchar(10), bar varchar(10) First, let's define our record class in a new module named "Simple.pm". use warnings; use strict; package Simple; use Jifty::DBI::Schema; use Jifty::DBI::Record schema { column foo => type is 'text'; column bar => type is 'text'; }; # your custom code goes here. 1; Like all perl modules, this needs to end with a true value. Now, on to the code that will actually *do* something with this object. This code would be placed in your Perl script. use Jifty::DBI::Handle; use Simple; Use two packages, the first is where I get the DB handle from, the latter is the object I just created. my $handle = Jifty::DBI::Handle->new(); $handle->connect( driver => 'Pg', database => 'test', host => 'reason', user => 'mhat', password => '' ); Creates a new Jifty::DBI::Handle, and then connects to the database using that handle. Pretty straight forward, the password '' is what I use when there is no password. I could probably leave it blank, but I find it to be more clear to define it. my $s = Simple->new( handle => $handle ); $s->load_by_cols(id=>1); load_by_cols Takes a hash of column => value pairs and returns the *first* to match. First is probably lossy across databases vendors. load_from_hash Populates this record with data from a Jifty::DBI::Collection. I'm currently assuming that Jifty::DBI is what we use in cases where we expect > 1 record. More on this later. Now that we have a populated object, we should do something with it! ::Record automagically generates accessors and mutators for us, so all we need to do is call the methods. accessors are named "column"(), and Mutators are named "set_column"($). On to the example, just appending this to the code from the last example. print "ID : ", $s->id(), " "; print "Foo : ", $s->foo(), " "; print "Bar : ", $s->bar(), " "; That's all you have to to get the data, now to change the data! $s->set_bar('NewBar'); Pretty simple! That's really all there is to it. Set<Field>($) returns a boolean and a string describing the problem. Lets look at an example of what will happen if we try to set a 'Id' which we previously defined as read only. my ($res, $str) = $s->set_id('2'); if (! $res) { ## Print the error! print "$str "; } The output will be: >> Immutable column Currently Set<Field> updates the data in the database as soon as you call it. In the future I hope to extend ::Record to better support transactional operations, such that updates will only happen when "you" say so. Finally, adding and removing records from the database. ::Record provides a Create method which simply takes a hash of key => value pairs. The keys exactly map to database columns. ## Get a new record object. $s1 = Simple->new( handle => $handle ); my ($id, $status_msg) = $s1->create(id => 4, foo => 'Foooooo', bar => 'Barrrrr'); Poof! A new row in the database has been created! Now lets delete the object! my $s2 = Simple->new( handle => $handle ); $s2->load_by_cols(id=>4); $s2->delete(); And it's gone. For simple use, that's more or less all there is to it. In the future, I hope to expand this how-to to discuss using container classes, overloading, and what ever else I think of. LICENSE
Jifty::DBI is Copyright 2005-2010 Best Practical Solutions, LLC. Jifty::DBI is distributed under the same terms as Perl itself. perl v5.14.2 2012-01-25 Jifty::DBI(3pm)
All times are GMT -4. The time now is 04:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy