Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

While loop help

👤 Login to reply

    #1  
Old 03-22-2017
rpiboy rpiboy is offline
Registered User
 
Join Date: Mar 2017
Last Activity: 22 March 2017, 7:44 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
While loop help

I'm trying to understand this code. I want to know when I execute the code how come this code outputs
"nameserver 192.168.168.2 search lan"?
There is no "cat /etc/resolv.conf" in the code so why does it output the content of the file?


Code:
#!/bin/bash
file=/etc/resolv.conf
while IFS= read -r line    # IFS : inter field separator
do
   # echo line is stored in $line
  echo $line
done < "$file"

Sponsored Links
    #2  
Old 03-22-2017
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 21 July 2018, 8:55 PM EDT
Location: Foxborough, MA
Posts: 8,314
Thanks: 260
Thanked 842 Times in 786 Posts
Quote:
Originally Posted by rpiboy View Post
I'm trying to understand this code. I want to know when I execute the code how come this code outputs
"nameserver 192.168.168.2 search lan"?
There is no "cat /etc/resolv.conf" in the code so why does it output the content of the file?


Code:
#!/bin/bash
file=/etc/resolv.conf
while IFS= read -r line    # IFS : inter field separator
do
   # echo line is stored in $line
  echo $line
done < "$file"

you don't need cat /etc/resolve.conf.
You're read your input through: done < "$file"
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk loop using array:wish to store array values from loop for use outside loop klane Shell Programming and Scripting 2 12-19-2013 03:25 PM
Reset while loop to loop same file multiple times tmalik79 Shell Programming and Scripting 4 10-09-2013 10:34 AM
Array Variable being Assigned Values in Loop, But Gone when Loop Completes??? mrm5102 Shell Programming and Scripting 5 10-19-2012 10:00 AM
Null Handling in Until loop. . .loop won't stop brandono66 Shell Programming and Scripting 4 11-24-2009 03:57 PM
Using variables created sequentially in a loop while still inside of the loop [bash] DeCoTwc Shell Programming and Scripting 2 06-23-2009 04:59 PM



All times are GMT -4. The time now is 08:59 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?