If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Bourne Shell help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-05-11, 04:45
mintos123 mintos123 is offline
Registered User
 
Join Date: Oct 2011
Posts: 1
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 07:24.
Reply With Quote
  #2 (permalink)  
Old 10-05-11, 08:13
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On