Unix Shell - extracting a quoted word from a string using bash

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2005 > extracting a quoted word from a string using bash





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author extracting a quoted word from a string using bash
turnernigel@hotmail.com

2005-10-24, 3:45 pm

Hello,

I'm using Kate text editor v2.4.1 under SuSE 10.0 out of the box. Here
is my script to extract the quoted word from a string. The word I want
in this case is Springfield. The script works as expected but the
editor highlights everything in red from the first quote leaving the
remaing script ambiguous. I have only included the relevant part of
the script here.

Is anyone able to help me correct this "feature" or adjust my script
please? Is there another way of getting the desired effect?


#!/bin/bash

line='I will not say "Springfield" just to get applause'

tmp1=${line#*\"}
tmp2=${tmp1%\"*}

echo $line
echo "the quoted word is:" $tmp2

Janis Papanagnou

2005-10-24, 3:45 pm

turnernigel@hotmail.com wrote:
> Hello,
>
> I'm using Kate text editor v2.4.1 under SuSE 10.0 out of the box. Here
> is my script to extract the quoted word from a string. The word I want
> in this case is Springfield. The script works as expected but the
> editor highlights everything in red from the first quote leaving the
> remaing script ambiguous. I have only included the relevant part of
> the script here.


The problem with scripts is that they are very cryptic and any syntax
highlighting is usually quite ambitious to implement.

If you have problems with syntax highlighting of your editor the best
thing you can do is asking in the comp.editors newsgroup or contact the
people where the editor is from to report some bug if it's not working
as specified.

> Is anyone able to help me correct this "feature" or adjust my script
> please? Is there another way of getting the desired effect?


That's the worst approach; to change a program to fit the deficiency of
some editor. Don't do that!

You might want to check other editors which might do a better job with
syntax highlighting and otherwise. Linux distributions are shipped with
a lot of editors.

Janis
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com