LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 06-28-2009, 02:55 PM   #1
ytnexus
LQ Newbie
 
Registered: Jun 2009
Posts: 2

Rep: Reputation: 0
Shell Script Question


is it possible to use input from a txt file as a variable in a shell script, basically what I want to do is take the information form a txt file (in this case a list of directory and files) and have a loop go through line by line and delete the files within the txt file;

exmp;

txt-file
/home/username/txt.1
/home/username2/txt.1
/home/username2/txt.2


what I would like to do is have it delete these files. My inital example script is ;

Code:
#!/bin/bash
echo "Enter String To Search For"
read string
echo "Enter directory to search in"
read dir
echo " Scanning $dir for $string"
grep -Hr $string $dir | cut -d: -f1 >> infected
cat infected | more
echo "Shall i delete these files"
read ans
if [ $ans = y] then;
  [command]
fi
if [ $ans = n] then;
 [command]
fi
which is made to take the String from a iframe injection/javascript injection grep the files for it and output the grep data to a file called "injected" I would like to then take the input from the "infected" file to gradually delete the files listed in the txt file. Problem is I can only find a way to make it look on a pure hard coded option within the script

Code:
for name in tim dick harry
do 
  echo "$name
done
I am looking to be able to take the for name option and use it for the main script, but pull the data from the txt file "infected" any one have any ideas?
 
Old 06-28-2009, 03:33 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Why not:
Code:
IFS='
' for name in $(< txt-file)
…
P.S.
The canonical metasyntactic variables are tom, dick and harry.

Last edited by osor; 06-28-2009 at 09:22 PM.
 
Old 06-28-2009, 04:28 PM   #3
ytnexus
LQ Newbie
 
Registered: Jun 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by osor View Post
Why not:
Code:
for name in $(< txt-file)
P.S.
The canonical metasyntacticvariables are tom, dick and harry.
osar, thank you very much, very very helpful, and yeah, i ment tom, fingers wanted tim. Thanks again for the help.
 
Old 06-28-2009, 09:22 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Btw, if your filenames have spaces, you might have to change the internal field separator.
 
  


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
shell script question icecubeflower Linux - Newbie 4 03-31-2009 06:24 AM
question about shell script tmbigrigg Linux - Newbie 4 11-05-2007 02:35 PM
Shell script question... defa0009 Linux - General 7 04-26-2005 08:16 PM
Help me!!!!!shell script question!!!!!! yulitao Programming 2 03-23-2004 03:40 PM
Shell script question rytrom Linux - Newbie 4 01-28-2004 07:20 AM


All times are GMT -5. The time now is 06:18 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration