Thread: Script File

  1. #1
    Registered User
    Join Date
    Oct 2009

    Unhappy Script File

    My teacher gave us this assigment and he is very vague on his questions. But the question reads write the largest script file that calculates the smallest of three integer numbers that are read from the keyboard. Make it able to recongnize some input errors. I guess he does care what type of errors they are as long as they can be read. The problem is I don't know at all how to do that part of the assigment.
    #This program accepts three numbers and shows the largest of them
    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"
       echo "The largest number is: $num1"
    elif test "$num2" -gt "$num1" -a "$num2" -gt  "$num3"
       echo "The largest number is:$num2"
      echo "The largest number is:$num3"
    echo "done!"
    exit 0

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    You can use functions, arrays, and POSIX regular expressions in bash scripts:
    function testnumber {
    	if [[ $1 =~ "^[[:digit:]]+$" ]]; then
    		return 1;
    	elif [[ $1 =~ "^[[:digit:]]+[.][[:digit:]]+$" ]]; then
    		return 1;
    		return 0;
    testray=(1.5 x 14 4f7 this 2 666 1.3.4)
    for e in ${testray[@]}; do
    	testnumber $e;
    	if [[ $? > 0 ]]; then
    		echo $e
    This accepts integers and decimal numbers. Return values with bash are wierd -- unless you are returning a single number <256, you need to set a global. But here that's okay, so we use $?, which is the return value of the last executed function.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM