The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
parameters jaay Shell Programming and Scripting 4 04-14-2008 05:10 AM
sed and parameters scotty_123 Shell Programming and Scripting 7 03-26-2007 05:22 AM
Max NO of parameters Shivdatta Shell Programming and Scripting 1 07-24-2006 09:11 AM
Need Parameters Help. james2006 Shell Programming and Scripting 3 06-08-2006 11:46 AM
tar parameters kmar UNIX for Advanced & Expert Users 4 10-23-2001 04:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-09-2006
aekaramg20 aekaramg20 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 9
parameters

I have a script that needs to check if the given parameters are a combination of 0123456789 and not a word or another irelevant character.please help
  #2 (permalink)  
Old 07-09-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360

Code:
#!/bin/sh

for vi in "$@"
do
    if [ "`echo $vi | sed 's/^[0-9]*$//'`" != "" ]; then
        echo "ERROR: invalid parameter: "$vi;
    fi
done

  #3 (permalink)  
Old 07-09-2006
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,242
bash/ksh


Code:

a="$*"
if [[ ${#a} -eq $(expr "$a" : '[0-9 ]*') ]] ; then
        echo numbers
else
        echo non-number
fi

  #4 (permalink)  
Old 07-10-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,429
Another solution (for KSH)


Code:
for arg in "$@"
do
   if [[ "$arg" = +([0-9]) ]]
   then
      echo "Valid parameter <$arg>"
   else
      echo "Invalid parameter <$arg>"
   fi
done


Jean-Pierre.
  #5 (permalink)  
Old 07-10-2006
aekaramg20 aekaramg20 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 9
is there anything for tcsh please?
  #6 (permalink)  
Old 07-10-2006
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,242
I'm really not a fan of tcsh, but anyway:


Code:
#!/bin/tcsh

set a = "$*"
if ( `expr "$a" : '.*'` == `expr "$a" : '[0-9 ]*'` ) then
    echo numbers
else
    echo non-number
endif

  #7 (permalink)  
Old 07-11-2006
vish_indian vish_indian is offline
Registered User
  
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 92
Quote:
Originally Posted by aekaramg20
I have a script that needs to check if the given parameters are a combination of 0123456789 and not a word or another irelevant character.please help
Another method(using awk):

for var in $@; do
if [[ `echo $var | awk -v var=${var} 'BEGIN{if(var!~/[[:digit:]]/)print 1;}'` -eq 1 ]]; then
echo "Not a number"
exit 0
fi
done
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0