LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices


Reply
  Search this Thread
Old 04-28-2015, 05:30 AM   #1
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Rep: Reputation: 0
ksh scripting question - loop works on linux, but not aix


Morning,

this might be an easy question but in the script below, when I wrap the function calls in a while true loop, the selected option is not processed. Not sure why as it works fine on linux. Thanks in advance - DG.

#!/usr/bin/ksh

show_options() {
clear
echo "====================="
echo " M A I N - M E N U "
echo "====================="
echo ""
echo "1 - Sync Training System"
echo "2 - Sync Live System"
echo "3 - Exit"
echo ""
}

read_options() {
local choice
echo "Enter choice [ 1 - 3] " choice
read choice

case $choice in
1) echo "picked 1" ;;
2) echo "picked 2" ;;
3) exit 0 ;;
*) echo "${RED}Error...${STD}" && sleep 2
esac
}


# while true
# do
show_options
read_options
# done

Last edited by danishgambit; 04-28-2015 at 05:31 AM.
 
Old 04-28-2015, 11:26 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
It works for me... Try to describe the problem more precisely.
PS: please use [code] and [/code] tags

Last edited by NevemTeve; 04-28-2015 at 11:27 AM.
 
Old 04-29-2015, 02:29 AM   #3
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
Morning,

as requested, some more details. I'd written this script on a linux box for bash and it works fine. However, when I ship it across to an aix box running the ksh shell and run it, nothing happens for the option 1 and 2 in the case statement, although 3 does exit. When I comment out the while loop it works fine (i.e. the echo'ed text appears then the script exits (as it would when not in the loop). Looks like wrapping the read command or case statement in the while loop is causing some different behaviour and I'm not able to figure out why.

Regards,

DG
 
Old 04-29-2015, 05:21 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
What would you expect to happen? Add some waits to your code.
Code:
case $choice in
1) echo "picked 1"; sleep 1 ;;
2) echo "picked 2"; sleep 1 ;;
3) exit 0 ;;
*) echo "${RED}Error...${STD}" && sleep 2
esac
}
 
Old 04-29-2015, 05:21 AM   #5
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,493

Rep: Reputation: Disabled
Different shells have slightly different syntax. There are many bash'isms in Linux that will not work in other shells/OSes.
Try writting it as #!/bin/sh, then it should work on all unix systems.
 
Old 04-29-2015, 09:38 AM   #6
wingnut64
Member
 
Registered: Sep 2004
Distribution: AIX, RHEL, Ubuntu
Posts: 51

Rep: Reputation: 23
Your script with the loop works fine for me on AIX using the stock ksh.

Quote:
Originally Posted by danishgambit View Post
nothing happens for the option 1 and 2 in the case statement, although 3 does exit. When I comment out the while loop it works fine
This is expected behavior. When you enter a number that does not cause the script to exit, it immediately runs show_options, and the first statement in show options is clear, which wipes the screen so you can't see what you just echoed. You can see it does actually echo text by doing a 'set -x' early in the script.
 
Old 04-30-2015, 02:36 AM   #7
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
thanks for the input guys.

to solve it I added a pause function, i.e.

pause () {
echo "Press enter key to continue...."
read userkey
}

and called this from within option 1 and 2.

Thanks for the help.

Regards,

DG.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ksh scripting question unix1adm AIX 5 10-05-2010 08:10 AM
solaris 10 ksh scripting question tobyl Solaris / OpenSolaris 8 05-21-2008 01:59 PM
Case Statement With Aix Ksh Scripting ']['HeBroken AIX 2 02-09-2005 12:44 PM
This is an AIX scripting question but I'm hoping somene can help XtremeDawg Programming 12 12-22-2003 02:45 PM

LinuxQuestions.org > Forums > Other *NIX Forums > AIX

All times are GMT -5. The time now is 11:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration