Ray Parrish | 1 Feb 2010 01:36

Re: Retaining leading white space when passing string values.

Todd A. Jacobs wrote:
> On Sun, Jan 31, 2010 at 02:18:17PM -0800, Ray Parrish wrote:
>
>   
>> Why??? It also does not work if I echo ${LineData[LoopCount]}... all
>> of  the leading spaces disappear.
>>     
>
> I think it's because the read bash built-in is using IFS to split words,
> which is one of the reasons I suggested treating the string as a stream
> rather than as a read loop. See this:
>
>     http://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html
>
> for why you're losing spaces. Of course, if you're trying to concatenate
> lines, losing the spaces is actually a Good Thing (tm), but if you
> really need them, read on.
>
> You can fix this by setting IFS to an empty string, but that might mess
> up something else in your script later on unless you unset IFS again
> after the while loop.
>
> So:
>
>     IFS=''
>     while read; do
> 	:
>     done
>     unset IFS
>
(Continue reading)

Ray Parrish | 2 Feb 2010 10:44

if will not work...

Hello,

I am going nuts trying to figure out why the following does not work...

    ThisLine=" ,"

     if [[ "$ThisLine" == " ." ]]
         then
               ThisBlockType="BlankLine"
     fi

ThisLine is actually being read in from a variable in a loop, and I am 
echoing it's value immediately before the if statement into a debug 
file. I can see that if is set to one space followed by a period, yet 
the damn thing will not trigger the if statement, and give me the value 
for ThisBlockType that I need at that point.

Anybody got any clues why???

Thanks for any light you can shed on the problem.

Later, Ray Parrish

--

-- 
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
(Continue reading)

Cameron Simpson | 2 Feb 2010 12:03
Picon
Picon
Gravatar

Re: if will not work...

On 02Feb2010 01:44, Ray Parrish <crp@...> wrote:
| I am going nuts trying to figure out why the following does not work...
| 
|    ThisLine=" ,"

That's a comma.

|     if [[ "$ThisLine" == " ." ]]

That's a period.

Not the same.

Cheers,
--

-- 
Cameron Simpson <cs@...> DoD#743
http://www.cskk.ezoshosting.com/cs/

A little rudeness and disrespect can elevate a meaningless interaction to a
battle of wits and add drama to an otherwise dull day!! - Calvin
Ray Parrish | 2 Feb 2010 15:19

Re: if will not work...

Cameron Simpson wrote:
> On 02Feb2010 01:44, Ray Parrish <crp@...> wrote:
> | I am going nuts trying to figure out why the following does not work...
> | 
> |    ThisLine=" ,"
>
> That's a comma.
>
> |     if [[ "$ThisLine" == " ." ]]
>
> That's a period.
>
> Not the same.
>
> Cheers
>   
Good eyes!!!  I have a hard time with small fonts seeing what is what. 
Thanks for helping.

Now maybe you could help with something else. All of a sudden the script 
I have beein working on started tossing errors left and right over stuff 
that was fine just minutes before.

It's complaining about < characters in the HTML markup I am writing to 
disk, and also it no lnger likes me using a line feed in the middle of a 
string assignment to force a line feed in the output. What the hell is 
going on???

Here is a sample error message -

(Continue reading)

Todd A. Jacobs | 2 Feb 2010 15:49
Favicon

Re: if will not work...

On Tue, Feb 02, 2010 at 06:19:50AM -0800, Ray Parrish wrote:

> /home/ray/Bashscripts/TestFunction.sh: line 278: syntax error near
> unexpected token `<' /home/ray/Bashscripts/TestFunction.sh: line 278:
> `                TableBody="$TableBody<tr><td style=\"padding: 10px;\"
> colspan=\"2\">'

All your problems tend to be quoting problems. < and > are reserved
symbols for the shell, and need to be quoted or escaped. TableBody
starts with a double quote, and ends with a single quote. That can't be
right.

You really need to use a text editor like VIM that will do syntax
highlighting and find matching symbol pairs so that this sort of error
gets caught visually.

--

-- 
"Oh, look: rocks!"
	-- Doctor Who, "Destiny of the Daleks"
Ray Parrish | 2 Feb 2010 17:31

Re: if will not work...

Todd A. Jacobs wrote:
> On Tue, Feb 02, 2010 at 06:19:50AM -0800, Ray Parrish wrote:
>
>   
>> /home/ray/Bashscripts/TestFunction.sh: line 278: syntax error near
>> unexpected token `<' /home/ray/Bashscripts/TestFunction.sh: line 278:
>> `                TableBody="$TableBody<tr><td style=\"padding: 10px;\"
>> colspan=\"2\">'
>>     
>
> All your problems tend to be quoting problems. < and > are reserved
> symbols for the shell, and need to be quoted or escaped. TableBody
> starts with a double quote, and ends with a single quote. That can't be
> right.
>
> You really need to use a text editor like VIM that will do syntax
> highlighting and find matching symbol pairs so that this sort of error
> gets caught visually.
>   
I use gedit, which does syntax highlighting, and brace matching. I'm not 
sure what blew up my script yet. I got tired of scrolling up and down in 
it looking for the possible culprit.

It was working fine, then all of a sudden after a few changes it blew 
up! It may be mismatched case, and esac pairs. I've used find in gedit 
to count them several times, and I'm pretty sure it keep coming out 37 
esac, 38 case, but I'm a bit tired so I'm not really sure if I counted 
accurately.

The script is so big it's difficult to match the case esac pars to each 
(Continue reading)

Ken Irving | 2 Feb 2010 18:29
Picon

Re: if will not work...

On Tue, Feb 02, 2010 at 08:31:29AM -0800, Ray Parrish wrote:
...
> 
> It was working fine, then all of a sudden after a few changes it
> blew up! It may be mismatched case, and esac pairs. I've used find
> in gedit to count them several times, and I'm pretty sure it keep
> coming out 37 esac, 38 case, but I'm a bit tired so I'm not really
> sure if I counted accurately.
> 
> The script is so big it's difficult to match the case esac pars to
> each other. Bash isn't heping much, as al it complains of now is
> that the done at the bottom of my while loop, and nearly the end of
> the script is unexpected, and I have no idea what's causing the
> error.
> 
> I used search and replace to replace all of the single quotes with
> double quotes, and still no joy.

Very minor typos very commonly yield vast amounts of error output, as
you know.  The fact that the complaint references the end of the script
sounds like bash is trying to find a matching symbol, whether a quote, 
paren, some kind of bracket, etc.  One stupid trick I've found useful is
just to search for the next double or single quote, then jump through the
code from one quote to the next visually checking that they match.

Good luck!

Ken
Cameron Simpson | 2 Feb 2010 23:40
Picon
Picon
Gravatar

Re: if will not work...

On 02Feb2010 08:29, Ken Irving <ken.irving@...> wrote:
| On Tue, Feb 02, 2010 at 08:31:29AM -0800, Ray Parrish wrote:
| > It was working fine, then all of a sudden after a few changes it
| > blew up! It may be mismatched case, and esac pairs. I've used find
| > in gedit to count them several times, and I'm pretty sure it keep
| > coming out 37 esac, 38 case, but I'm a bit tired so I'm not really
| > sure if I counted accurately.
| > 
| > The script is so big it's difficult to match the case esac pars to
| > each other. Bash isn't heping much, as al it complains of now is
| > that the done at the bottom of my while loop, and nearly the end of
| > the script is unexpected, and I have no idea what's causing the
| > error.
| > 
| > I used search and replace to replace all of the single quotes with
| > double quotes, and still no joy.
| 
| Very minor typos very commonly yield vast amounts of error output, as
| you know.  The fact that the complaint references the end of the script
| sounds like bash is trying to find a matching symbol, whether a quote, 
| paren, some kind of bracket, etc.  One stupid trick I've found useful is
| just to search for the next double or single quote, then jump through the
| code from one quote to the next visually checking that they match.

Yes.

You should also always syntax your script before running it:

  sh -n your-script

(Continue reading)

bsd | 4 Feb 2010 17:59

Deleting from named.conf

Hello, 

I am hosting a large zone file (named.conf) and need to create a script to delete zones when they are no longer
used. 
Zones inside the file looks like that: 

zone "abc.com" {
        type slave; 
        masters  { 213.14.17.2 ; };
        file "hosts.abc.com";
};

zone "def.fr" {
        type slave; 
        masters  { 23.174.17.2 ; };
        file "hosts.def.fr";
};

zone "xyz.net" {
        type slave; 
        masters  { 23.74.27.2 ; };
        file "hosts.xyz.net";
};

I would need the script to delete the whole block after the zone definition… 

What aproach would you suggest ? 

I was thinking of using sed but I don't know how to use It in multi-line approach ?

(Continue reading)

Ken Irving | 4 Feb 2010 19:21
Picon

Re: Deleting from named.conf

On Thu, Feb 04, 2010 at 05:59:56PM +0100, bsd wrote:
> Hello, 
> 
> I am hosting a large zone file (named.conf) and need to create a script to delete zones when they are no
longer used. 
> Zones inside the file looks like that: 
> 
> 
> zone "abc.com" {
>         type slave; 
>         masters  { 213.14.17.2 ; };
>         file "hosts.abc.com";
> };
> 
> zone "def.fr" {
>         type slave; 
>         masters  { 23.174.17.2 ; };
>         file "hosts.def.fr";
> };
> 
> zone "xyz.net" {
>         type slave; 
>         masters  { 23.74.27.2 ; };
>         file "hosts.xyz.net";
> };
> 
> I would need the script to delete the whole block after the zone
> definition?
>
> What aproach would you suggest ?
(Continue reading)


Gmane