Shell scripting: read one line at a time from keyboard

by nixcraft on March 7, 2006 · 1 comment

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)

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 1 comment… read it below or add one }

1 jalal hajigholamali August 3, 2011

thanks…

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 2 + 3 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.



Previous post:

Next post: