LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-17-2009, 03:16 PM   #1
mpmackenna
Member
 
Registered: May 2006
Posts: 69

Rep: Reputation: 15
Basic Bash Script help


I am banging my head on this one and I know it is right in front of my face, but I swear I can't find nor remember how to do this...

All I want to do is substitute lines of a text file into an existing command. Can someone please help me....

Example,
File contains
foo
bar
cat
hat

Execute commands....

rm -rf ~/tmp/$var/*

over and over so I get the commands

rm -rf ~/tmp/foo/*
rm -rf ~/tmp/bar/*
rm -rf ~/tmp/cat/*
rm -rf ~/tmp/hat/*

Thanks so much!

Mike
 
Old 03-17-2009, 03:53 PM   #2
weibullguy
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
Something like this?
Code:
while read subdir;
do
rm -rf ~/tmp/$subdir/*
done < file_with_subdirs_in_it
 
Old 03-17-2009, 03:54 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,114

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
Code:
for var in foo bar cat hat
# for var in `cat var.lst`
do
 echo var = $var
 # rm -rf ~/tmp/$var/*
done

Last edited by schneidz; 03-17-2009 at 03:56 PM.
 
Old 03-18-2009, 10:23 AM   #4
mpmackenna
Member
 
Registered: May 2006
Posts: 69

Original Poster
Rep: Reputation: 15
Wow

Two answers... both equally good. Thanks so much! Mike
 
  


Reply


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
Basic bash script question kevpatts Linux - Newbie 3 10-12-2005 01:02 PM
Basic Bash script help valadamir Programming 2 12-01-2004 10:37 AM
Trouble with a basic bash script Tengil Linux - Newbie 5 03-04-2004 12:59 PM
Basic BASH script, what's wrong??? Satriani Linux - General 2 06-02-2003 05:34 PM
help with basic syntax in bash script Supp0rtLinux Linux - Software 4 03-27-2003 06:57 PM


All times are GMT -5. The time now is 08:53 AM.

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