Shell scripting: read one line at a time from keyboard

by on March 7, 2006 · 1 comment· last updated at March 7, 2006

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)



You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 1 comment… read it below or add one }

1 jalal hajigholamali August 3, 2011 at 4:10 pm

thanks…

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as:

Previous Faq:

Next Faq: