Okay so basically I want to be able to use a text file with this format:
www.website.com 443 123.456.789.098
www.website2.com 443 765.432.101.234
....
as a source of input in which the script will take the website address and hold it in a variable and the same thing with the port and Ip address. So it would look like this:
website=www.website.com
port=443
ip=123.456.789.098
So far, I have tried this:
for line in [ cat $file_name ]; do
website=`echo $line | cut -d" " -f1`
port=`echo $line | cut -d" " -f2`
ip=`echo $line | cut -d" " -f1`
But when i echo out the the variables all i get is this:
[
[
[
I can’t seem to figure out how to go about solving this issue.
Use this pattern instead:
Explanation:
for var in word-listwill assign the words in the list to the variable in order. So for the first loop,$linewill expand to[(first word in the list). The next word would becatand then the value offile_name.To read from a file, you need to use I/O redirection.
while, on the other hand, will execute the command that you passed as argument (read line).readwill read one line fromstdinand put the value into the variable that you passed as argument.The odd
done < $file_namesets thestdinfor read. And to make you life even more simple, you can usereadto split the input for you: