Unix/Linux Go Back    


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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-22-2017   -   Original Discussion by rpiboy
rpiboy's Unix or Linux Image
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 Unix and Linux 03-22-2017   -   Original Discussion by rpiboy
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 22 January 2018, 3:18 PM EST
Location: Foxborough, MA
Posts: 8,204
Thanks: 231
Thanked 786 Times in 733 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
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 04:25 PM
Reset while loop to loop same file multiple times tmalik79 Shell Programming and Scripting 4 10-09-2013 11:34 AM
Array Variable being Assigned Values in Loop, But Gone when Loop Completes??? mrm5102 Shell Programming and Scripting 5 10-19-2012 11:00 AM
Null Handling in Until loop. . .loop won't stop brandono66 Shell Programming and Scripting 4 11-24-2009 04: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 05:59 PM



All times are GMT -4. The time now is 05:52 PM.