Shell scripting: read one line at a time from keyboard
Sometime it is necessary to read one line from a file or keyboard. We have Shell script utility to read a file line by line here and here. However, you can use line command to do same thing.
For example, read one line from keyboard and store to variable called na:
$ na=$(line)
Howdy Guest
$ echo $na
Output:
Howdy Guest
The utility line copies one line (up to a newline) from standard input (keyboard) to standard output (screen). It always prints at least a newline and returns an exit status of 1 on EOF or read error.
You can easily use line command in a shell scripts.
(Check out all of our posts on Shell Scripting)
E-mail this to a friend
Printable version
Related Other Helpful FAQs:
- How do you take a single line of input from the user in a shell script?
- Linux script to prompt for password
- Moving Around With vim (keyboard short cuts)
- Gnome Desktop Keyboard Shortcut Keys
- How to read a file line by line using awk
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!



Recent Comments
Yesterday ~ 1 Comment
Yesterday ~ 10 Comments
Yesterday ~ 12 Comments
09/03/2008 05:29 pm (2 days ago) ~ 6 Comments
09/03/2008 01:14 pm (2 days ago) ~ 1 Comment