The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
assign awk's variable to shell script's variable? tiger2000 Shell Programming and Scripting 3 4 Weeks Ago 04:47 AM
Insert a line including Variable & Carriage Return / sed command as Variable lowmaster Shell Programming and Scripting 2 05-20-2009 12:26 AM
Sed variable substitution when variable constructed of a directory path alrinno Shell Programming and Scripting 2 07-11-2008 03:24 PM
Enviornment Variable in B shell (I call it nested variable) princelinux Shell Programming and Scripting 4 07-02-2008 02:35 AM
passing a variable inside a variable to a function KingVikram UNIX for Dummies Questions & Answers 2 01-14-2008 08:28 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 3 Weeks Ago
chebarbudo's Avatar
chebarbudo chebarbudo is offline
Registered User
  
 

Join Date: Nov 2008
Location: various
Posts: 188
Ooops, in my real script, I'm not using the file as it is but I grep it first.
What's the correct syntax to use then?
Code:
r29829:~# cat conf
# comment
A=1
B=2
# C is set to three
C=3
r29829:~# cat testconf.sh
#!/bin/bash
while IFS="=" read lvalue rvalue; do
        eval $lvalue=$rvalue
done < grep -v '^#' conf
echo "-$A-$B-$C-"
r29829:~# ./testconf.sh
./testconf.sh: line 4: syntax error near unexpected token `-v'
./testconf.sh: line 4: `done < grep -v '^#' conf'
  #2 (permalink)  
Old 3 Weeks Ago
Scrutinizer Scrutinizer is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 673
Hi Chebarbudo,
in bash (and only in bash) the correct syntax would be:
Code:
#!/bin/bash
while IFS="=" read lvalue rvalue; do
        eval $lvalue=$rvalue
done < <(grep -v '^#' conf)
echo "-$A-$B-$C-"
An alternative that also works in other shells would be:
Code:
grep -v '^#' conf|
{ while IFS="=" read lvalue rvalue; do
        eval $lvalue=$rvalue
  done
  echo "-$A-$B-$C-"
}
  #3 (permalink)  
Old 3 Weeks Ago
chebarbudo's Avatar
chebarbudo chebarbudo is offline
Registered User
  
 

Join Date: Nov 2008
Location: various
Posts: 188
Hi Scrutinizer,

Thanks for your help, the bash syntax works fine.
Although do you know where I can find documentation for this type of redirection? So far I only knew the following:
|
>
>>
<
<<
<<<


Santiago
  #4 (permalink)  
Old 3 Weeks Ago
Scrutinizer Scrutinizer is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 673
Hi Santiago,

The redirection is a simple < together with process substitution

S.
Reply

Bookmarks

Tags
variable

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0