LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Basic Bash Script help (https://www.linuxquestions.org/questions/linux-newbie-8/basic-bash-script-help-712330/)

mpmackenna 03-17-2009 03:16 PM

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

weibullguy 03-17-2009 03:53 PM

Something like this?
Code:

while read subdir;
do
rm -rf ~/tmp/$subdir/*
done < file_with_subdirs_in_it


schneidz 03-17-2009 03:54 PM

Code:

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


mpmackenna 03-18-2009 10:23 AM

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


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