LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-11-2006, 06:28 PM   #1
blaoulis
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Rep: Reputation: 0
Shell Scripting Questions


Hey!!
I m using cshell and i want to examine if a string that i read is integer? Is there a function is_int() ? How can i do that with grep?

Secondly, How can i send mail via a script using the mail command?
( write subject + content)

Thx in advace!!
 
Old 07-11-2006, 08:34 PM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
I don't know about the first one, but the second one is easy. For subject just use the -s option with the subject following (quoted if it's more than one word). For content, just pipe the message to it on standard input.
 
Old 07-12-2006, 06:56 AM   #3
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 17
Posts: 150

Rep: Reputation: 18
With grep, you can check out the character classes (if you can't find it under grep, check regular expressions). [:digit:] or [:alnum:] is what I think you are want.
 
Old 07-12-2006, 10:42 AM   #4
blaoulis
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Original Poster
Rep: Reputation: 0
I tried something like this
Code:
#!/bin/csh

echo "$argv[1]" > $argv[1]
grep "[:alnum:]" $argv[1]
./isdigit 12
./isdigit dd123
dd123
./isdigit dddd
dddd
./isdigit 123s

It worked in all cases but the last one ( which is not digit ) does't work. any help?
 
Old 07-12-2006, 12:02 PM   #5
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
How about this pipeline:
Code:
echo "$argv[1]" | grep -E '^[[:digit:]]+$' | wc -l
This returns one when $argv[1] is a sequence of digits, or zero when it's not. Also, by piping the argument to grep on stdin you don't have to create a temporary file.
 
Old 07-12-2006, 07:21 PM   #6
blaoulis
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Original Poster
Rep: Reputation: 0
thx ,
I found another way doing this with sed!
Something else i want to ask,
there is a problem in csh with functions??

Code:
#!/bin/csh

usage()
{
echo "usage"
}
usage
./usage

Badly placed ()'s

I tried to replace usage() with function usage, but same problem.
Any help?

Edit:: Just Founded it ::
Csh does't support function only aliases!!!

Last edited by blaoulis; 07-12-2006 at 07:50 PM.
 
  


Reply



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
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
Two Linux shell scripting questions thepryme Programming 5 10-23-2003 07:01 AM
Help with Shell Scripting. eggoz Linux - General 2 04-21-2003 01:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:56 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