[SOLVED] ksh scripting question - loop works on linux, but not aix
AIXThis forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 ""
}
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.
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,493
Rep:
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.
Your script with the loop works fine for me on AIX using the stock ksh.
Quote:
Originally Posted by danishgambit
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.