• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

read command not working in ksh script

 
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to read from user input in a certain condition.
The script doesn't wait for user input at all.




The script prints
Please enter Name:
Name read from user:

I tried with many combination of "read" command like read -rn 0 NAME. Still not working.
 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this ksh issue?
Cause the same command read works in the console.
Is that when I try to run the same command inside from a ksh script it doesn't work at all.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly how are you running that script? Are you starting it from a command prompt, and if so, how are you starting it? There are various ways of starting a script where a different stdin that what you might expect is supplied, which could account for this behavior.
 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,
Thanks for your reply.

My script is like this:


I am calling the script in this way ...


Now this doesn't wait to take the user input.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you running the command from ksh or from bash?
 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running it from bash.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try running it from ksh. I think that when running it from bash, you end up with a new session with a different stdin, which is why you are not being prompted.
 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,
Thanks for your reply.
I keep on waiting for your reply.

Well, I just tried running from ksh shell too. I got the same issue.
This is what I did, I typed `which $SHELL` that returned me /bin/sh which means it's bash.
On my old shell I typed "ksh".
And then tried to execute the same script.


Now the point is, even if I typed ksh and the shell changed, but when I tried to run `which $SHELL` that returned me the same /bin/sh.
Do I have to set some path or something to point to ksh shell.

Thanks for your help. Much appreciated.
 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of my colleague figured this out for me.

There was a while loop in a different function which was like this:

`grep ... ` | while read word; do

# calling the function where I was using read command...


done

So just by changing the while to for loop that issue got resolved...
 
reply
    Bookmark Topic Watch Topic
  • New Topic