![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Need help with incrementing date in while loop. | Robert W.Mills | Shell Programming and Scripting | 3 | 08-05-2008 02:08 PM |
| No. post not incrementing | incredible | Post Here to Contact Site Administrators and Moderators | 5 | 07-22-2008 12:59 PM |
| Port num incrementing | coolkid | Shell Programming and Scripting | 5 | 05-28-2008 06:51 PM |
| New iteration of for-loop without incrementing? | jeriryan87 | Shell Programming and Scripting | 0 | 07-02-2007 03:13 PM |
| incrementing a for loop | run_time_error | Shell Programming and Scripting | 2 | 03-28-2005 03:45 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Incrementing in while loop
Code:
echo "Enter Starting id:" echo "" read rvst_strt_idxx echo "" echo "Enter Closing id:" echo "" read rvst_clsn_idxx FIELD1=$rvst_strt_idxx FIELD2="USER" FIELD3="TEST" FIELD4="12345" FIELD5="00000" echo "" echo "INSERT INTO TABLE( FIELD1, FIELD2, FIELD3, FIELD4, FIELD5 ) " echo " VALUES ( '$FIELD1','$FIELD2','$FIELD3','$FIELD4',$FIELD5') " Suppose Starting id is 10 and closing Id is 20 I want to write a script which will increment the value of field1 in each loop starting with 10 and increment until 20 is reached ie I need 20 lines of Insert into scripts which will have field1 values from 10 to 20 I think i need to write a while loop which increments the value of field 1 by 1 and until it reaches the upper limit is (20 here). Please help Last edited by vidyadhar85; 06-10-2009 at 02:58 PM.. Reason: code tag added |
|
||||
|
Code:
echo "Enter Starting id:"
echo ""
read rvst_strt_idxx
echo ""
echo "Enter Closing id:"
echo ""
read rvst_clsn_idxx
while [[ $rvst_strt_idxx -le $rvst_clsn_idxx ]]
do
FIELD1=$rvst_strt_idxx
FIELD2="USER"
FIELD3="TEST"
FIELD4="12345"
FIELD5="00000"
echo ""
echo "INSERT INTO TABLE( FIELD1, FIELD2, FIELD3, FIELD4, FIELD5 ) "
printf "VALUES ( '%s', '%s', '%s', '%s', '%s' );\n" $FIELD1 $FIELD2 $FIELD3 $FIELD4 $FIELD5
rvst_strt_idxx=$(( $rvst_strt_idxx + 1 ))
done > output.sql
try something like this. |
|
|||||
|
you can get rid of few more lines
1)if your FIELD2,FIELD 3...FIELD5 are fixed use the values directly in printf i mean no need to assign them to variable and use it 2)there is no need to assingn $start to n 3)n=$(( $n + 1 )) is <===> n=$((n+1)) |
|
|||||
Quote:
Quote:
Quote:
|
|
|||||
|
It depends on individual
wheather he want to circle around variable like early 80's people used to do at the end of the day they used to spend more time to give a name to variable rathere than the logic of the program and I don't think lines are cheap for every one ![]() I belive in doing 1+1 as 1+1 not as A=1;B=1 c=A+B |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|