Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Unanswered: Bourne Shell help

    i am trying to write a script which it echos its script file name and the value of its odd arguments.
    i got the echo filename part..but im not sure how to echo its odd arguements.
    for example
    the output of script Good_script is a very good script
    should be
    Good_script
    is
    very
    script

    i have came up with code
    Code:
    #!/bin/sh
    filename=`basename $0`;
    echo $filename;
    i=1
    	until [ $i -gt $# ]
    	do
     	y=`echo "$i % 2" | bc`
     		if [ $y -eq 1 ]; then
    		echo $i
    		fi
    	i=`echo "$i + 1" | bc`
    	done
    but right now, it only echos the filename and the numerical value
    say if it was Good_script a b c d e
    it would output
    Good_script
    1
    3
    5
    any help?
    Last edited by mintos123; 10-05-11 at 08:24.

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Code:
    #!/bin/sh                            
    filename=`basename $0`;              
    echo $filename;                      
    last=$#                              
    i=1                                  
            until [ $i -gt $last ]       
            do                           
            y=`echo "$i % 2" | bc`       
                    if [ $y -eq 1 ]; then
                    echo $i $1           
                    fi                   
            shift                
            i=`echo "$i + 1" | bc`       
            done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •