![]() |
| | #1 | |
| Registered User Join Date: Oct 2009
Posts: 16
| Quote:
Code: #This program accepts three numbers and shows the largest of them # echo echo "Enter three numbers and I will show you the largest of them>> \c" read num1 num2 num3 if test "$num1" -gt "$num2" -a "$num1" -gt "$num3" then echo "The largest number is: $num1" elif test "$num2" -gt "$num1" -a "$num2" -gt "$num3" then echo "The largest number is:$num2" else echo "The largest number is:$num3" fi echo "done!" echo exit 0 | |
| victory1 is offline | |
| | #2 |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,225
| You can use functions, arrays, and POSIX regular expressions in bash scripts: Code: #!/bin/bash
function testnumber {
if [[ $1 =~ "^[[:digit:]]+$" ]]; then
return 1;
elif [[ $1 =~ "^[[:digit:]]+[.][[:digit:]]+$" ]]; then
return 1;
else
return 0;
fi
}
testray=(1.5 x 14 4f7 this 2 666 1.3.4)
for e in ${testray[@]}; do
testnumber $e;
if [[ $? > 0 ]]; then
echo $e
fi
done
|
| MK27 is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| gcc link external library | spank | C Programming | 6 | 08-08-2007 03:44 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C Programming | 3 | 03-04-2005 02:46 PM |
| Possible circular definition with singleton objects | techrolla | C++ Programming | 3 | 12-26-2004 10:46 AM |
| System | drdroid | C++ Programming | 3 | 06-28-2002 10:12 PM |
| Need a suggestion on a school project.. | Screwz Luse | C Programming | 5 | 11-27-2001 02:58 AM |