Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-27-2011, 08:39 PM   #1
LQ Newbie
Registered: Sep 2011
Posts: 2

Rep: Reputation: Disabled
script that manipulates input from user

I have to write a shell script that gets four lines of input from the user. The script should manipulate the input in various ways. One of the challenges is to determine which of the four lines is longest and to display that line. Can I use the cat command, redirect the input to a text file, and then go through the file to determine which line is the longest? I would also need to print this line.

Or do I need to read in 4 lines into 4 variables and work with them that way? The commands I know are limited so I am looking for a little bit of guidance.
Old 09-27-2011, 08:45 PM   #2
ReliaFree Maintainer
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
Old 09-27-2011, 08:52 PM   #3
LQ Newbie
Registered: Sep 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
yes it is
Old 09-27-2011, 09:07 PM   #4
Registered: Jun 2005
Location: Kentucky
Distribution: Ubuntu
Posts: 794

Rep: Reputation: 56
First result explains how to determine line length in bash.

Old 09-27-2011, 09:36 PM   #5
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Here's another good source for string manipulation information in bash. There's lots of good stuff you can do right inside the shell, once you have them stored in variables.

Another hint: instead of regular variables, have a look at arrays.

Of course if one of your requirements is that the script be portable (posix compliant), then you'll be much more limited in the techniques you can use. See here for some ideas on how to convert bash features to posix.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
user defined input in shell script ovaisalam Linux - Newbie 4 12-08-2010 06:44 AM
I cannot figure out how to get user input into a script froster Linux - Newbie 2 11-05-2009 07:13 PM
Shell script user input tuckermaddox Linux - Newbie 5 08-12-2004 03:14 AM
Masking user input in sh script? RMSe17 Linux - Software 3 07-20-2004 10:17 PM
User input using a BASH script... causticmtl Programming 5 07-13-2003 09:59 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:15 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration