While within while is not working in Korn shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While within while is not working in Korn shell
# 1  
Old 09-27-2019
While within while is not working in Korn shell

Hi all,

I tried to execute a while within another while, but not working. Any suggestions? Thanks in advance

Code:
#!/bin/ksh
 
typeset -i i=1
typeset -i j=1
 
while [[ $i -lt 4 ]]
do
   while [[ $j -lt 3 ]]
   do
      print i = $i j= $j
      (( j=j+1 ))
   done
   (( i=i+1))
done

I get result is

Code:
i = 1 j= 1
i = 1 j= 2

# 2  
Old 09-27-2019
j remains at value 3 once it reaches it. Reset to one just before the j loop.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 09-27-2019
You forgot to reset j
Code:
   j=1
   while [[ $j -lt 3 ]]

This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 09-27-2019
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Typeset is not working in Linux korn shell scripting

Hi All, Kindly help on the below issue ASAP. Its very urgent. I have script in which we have below two lines for code and it is not working. Please help. files_to_process=" abc_*.log def_*.log ghi_*.log " typeset -A dir_list ${files_to_process} the script is failing in Linux... (3 Replies)
Discussion started by: tvbhkishore
3 Replies

2. Shell Programming and Scripting

New to korn shell

I am new to korn shell and slowly learning. Is there a way to have a parent script prompt for input and then execute a child script and return the output then move forward and ask for more input and then execute the next child script? I think the answer is no but thought i would ask. (2 Replies)
Discussion started by: cptkirkh
2 Replies

3. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

4. Shell Programming and Scripting

MKS Korn shell not working when schedule

Hi I have a sample MKS Korn Shell script, it is working fine when I am executing manually (i.e command prompt) but not when schedule through scheduler. here is the script, ls command working just fine manual run, so I thought it could be environment varilable so kept same PATH when running... (1 Reply)
Discussion started by: rkthoka
1 Replies

5. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

6. Shell Programming and Scripting

putting ftp in korn function - no longer working

This works if it's not in a function. I pulled it into one and I get syntax error, no mathcing '<'. I have to call it several times and need it to be a function. Any ideas? function FTP_Engine_File { ftp -inv ${FTP_SERVER} << EOF_FTP >> ${FTP_LOG} user ${FTP_USER} ${FTP_PSWD} ... (4 Replies)
Discussion started by: brdholman
4 Replies

7. UNIX for Dummies Questions & Answers

korn shell to bash - statement not working

Everything else seems to be working, but this isn't. Is it the "cat..." that is wrong of the condition? Thanks. cat tc_result.txt | while read LINE do if then let "files_run += 1"; echo "inside the if loop" # save current filetype case $LINE... (5 Replies)
Discussion started by: brdholman
5 Replies

8. Shell Programming and Scripting

how to convert from korn shell to normal shell with this code?

well i have this code here..and it works fine in kornshell.. #!/bin/ksh home=c:/..../ input=$1 sed '1,3d' $input > $1.out line="" cat $1.out | while read a do line="$line $a" done echo $line > $1 rm $1.out however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Discussion started by: forevercalz
21 Replies

9. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies

10. Shell Programming and Scripting

Korn Shell

Hi I am new to shell programming. I need help to write a script to monitor a process on Sun OS. If the process fails then call a oracle procedure. i check the process if running by typing ps -ef | grep ESP | grep -v grep root 29002 1 0 Mar 18 ? 7:20... (4 Replies)
Discussion started by: gpanesar
4 Replies
Login or Register to Ask a Question