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 10-30-2007, 04:47 PM   #1
Registered: Oct 2007
Posts: 40

Rep: Reputation: 15
YASQ Yet Another Simple Question regarding scripting

my pwd contains files and directories named nick and emptydr

ls -l|grep dwrx|cut -d' ' -f9
returns the name of the directories in my pwd.

let's say I save the result of the above command into a file named listing.

then the file listing will contain the following"


and now, I would like to write my script so my script uses each line in the file named listing as the input of the file. How can I do that?

Old 10-31-2007, 10:16 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I think you want the "read" command.

For example, this:
read line1 < filename
reads the first line of "filename" into the variable "line1"

You could do it in a loop in which each invocation of "read" puts a line into an array, indexing the array as you go.

I recommend going to and getting the Advanced Bash Scripting Guide. Unless you have a personal forest, don't print it!! I just use it for searches.
Old 10-31-2007, 11:29 AM   #3
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
ls -l|grep dwrx
Better to use this:
ls -l| grep ^d
^d means lines beginning with d

and then using result (here I simply use echo to print each line):

cat file  | while read i; do echo $i; done


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
simple scripting question jerf Linux - Newbie 4 09-19-2007 04:12 AM
simple question regarding shell scripting branche_dude Linux - Newbie 8 07-21-2006 03:35 AM
Bash Scripting--Simple Question mooreted Linux - General 4 05-10-2004 02:44 PM
simple scripting question wedgeworth Programming 6 02-04-2004 11:30 AM
YASQ - yet another samba question itsjustme Linux - Networking 9 10-07-2003 05:45 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:43 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
Open Source Consulting | Domain Registration