Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bash 2.05b 1

Status
Not open for further replies.

veedevadu

Technical User
Oct 28, 2008
4
US
Hi!

I am using bash 2.05b. I have a script that uses =~ operator but it is not recognized in this version. It works fine on bash 3.2.x though. Can someone please let me know how to get around this?

Here is the code.

function (){
.......

local SEC="^\[$SECTION\]"
local KEYVALUE="^$KEY=(.*)"

while read line; do
if [ $section = 0 ]; then
if [[ $line =~ $SEC ]]; then
section=1
continue
fi
else
if [[ $line =~ $KEYVALUE ]]; then
echo ${BASH_REMATCH[1]}
return 0
fi
fi
done <"$FILE"
return 1
}

Thanks in advance.
 
To add further, I am looking for the change that runs on both versions.

Thanks a lot again in advance.
 
Why not simply use awk ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Pardon my ignorance but I am a novice in shell programming. I'll appreciate if you can help me out.

Thank you.
 
Hi

Code:
[b]function[/b] whatever()
{
  [b]local[/b] SEC=[i]"[$SECTION]"[/i]
  [b]local[/b] KEYVALUE=[i]"$KEY="[/i]
  [b]local[/b] section=0

  [b]while[/b] read line; [b]do[/b]
    [b]if[/b] (( section==0 )); [b]then[/b]
      [b]if[/b] [[ [i]"$line"[/i] == [i]"$SEC"[/i] ]]; [b]then[/b]
        section=1
        [b]continue[/b]
      [b]fi[/b]
    [b]elif[/b] [[ [i]"${line:0:${#KEYVALUE}}"[/i] == [i]"$KEYVALUE"[/i] ]]; [b]then[/b]
      echo [i]"${line:${#KEYVALUE}}"[/i]
      [b]return[/b] 0
    [b]fi[/b]
  [b]done[/b] < [i]"$FILE"[/i]
}
Tested with [tt]bash[/tt] 2.05b.0 and 3.2.39.

Note that I only rewrote it. I tried to keep the changes simple and clear. The code still has its original glitch.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top