« Return to Thread: Problems with Bash read on unslung

Re: Problems with Bash read on unslung

by bloedmann999 :: Rate this Message:

Reply to Author | View in Thread

--- In nslu2-linux@..., jl.050877@... wrote:

>
> On Sat, Jul 19, 2008 at 10:22:00AM -0000, bloedmann999 wrote:
> > Marcel,
> > thanks that works OK. Looking at the book I have on Bash I can only
> > see the the following that fits to this:
> >
> > B=${A:start:length}
> >
> > is that what this is doing, but as the start and length aren't there,
> > then the complete string is taken? Just wondering why bash works
> > differently for variables up to 9 and from 10 onwards.
>
> Look at the man page for Bash (on the web or on any system that has
> man installed) and it explains this, including the problem with
> two-digit parameters names.  From the section entitled "Parameter
> Expansion":
>
>     ${parameter}
>        The  value  of  parameter  is  substituted.   The braces  are
>        required when parameter is a positional  parameter with  more
>        than  one  digit, or when parameter is followed by a character
>        which is not to be interpreted as part of its name.
>
> John
>
Thanks I have that all working correctly now on debian and unslung. I
would like to hijack my own thead for a similar question on Bash.
I occasionally get a string passed to my script that has things like
this in it; `UNKNOWN'.
And that is causing me problems. So I though I would just translate
the characters I did not need to blanks, but the string above always
causes a syntax error of some kind or another. Looking at the Bash manual:
3.1.2.2 Single Quotes

Enclosing characters in single quotes (`'') preserves the literal
value of each character within the quotes. A single quote may not
occur between single quotes, even when preceded by a backslash.

So a single quote may not appear in the string, in mine it does. Also
I have no chance to translate to add backslashes, as it breaks
straight away.

Single quotes:
# ./parse-msgs-2.sh test '`UNKNOWN''
Syntax error: Unterminated quoted string

Double quotes:
# ./parse-msgs-2.sh test "`UNKNOWN'"
Syntax error: EOF in backquote substitution

From anothe point of view, the message itself is being produced by
login, for example:

Jul 25 12:40:55 SLUG1 login[3865]: invalid password for `UNKNOWN' on
`ttyp3' from `192.168.123.166'

Maybe there is a way to stop the message being produced with these
single quotes and ticks?

OTOH I would be very interested in a method to allow me to process
such a string if possible.

The testing of this was done on a Firmware Version:
V2.3R63-uNSLUng-6.8-beta, with bash - 3.2.33-1.

Cheers Brian






 














 « Return to Thread: Problems with Bash read on unslung

LightInTheBox - Buy quality products at wholesale price!