Simple Shell Script Help

Soldato
Joined
27 Aug 2004
Posts
2,955
Location
Singapore ExPat
Hey guys, I need a hand with a simple shell script (bash). I have a file that contains a list of servers each on a separate line, what I want to do is use each hostname as a variable to log into, create a directory, exit and repeat. Now I gather I probably need to use a while loop or for loop but am not sure of the correct way to get the hostnames into an array? Do I need to cat it?
Any pointers much appreciated.
 
Associate
Joined
5 Jun 2005
Posts
987
Location
Leicestershire
Given a file words.txt containing
word1
word2
word3

the following command:

Code:
for word  in $(cat words.txt); do echo "word is: $word" ; done

will produce the following output:

word is: test1
word is: test2
word is: test3

So you probably want

Code:
for dir  in $(cat dirs.txt); do mkdir $dir ; done

(Well, you need to sort out the login bits of course........ )

Hope that helps.
 
Last edited:
Back
Top Bottom