Unix Shell - Quotes nested inside bash

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2006 > Quotes nested inside 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 Quotes nested inside bash
Sven

2006-11-28, 7:29 am

Hi there,

I'm trying to run awk from the command line using the double-quote ["]
character as the delimiter.
When run from my shell, the following command works just fine:

awk -F\" '{print $2}' file.html

However, I am trying to call bash from an external application, so I
need to wrap the whole command in double-quotes, giving:

bash -c "awk -F\" '{print $2}' Img0003.html"

The above of course gives an error because my delimiting ["] closes the
bash command. I have tried many combinations of escape-char and
quote-char (such as "awk -F\\" ..."), but these all seem to either
error, or are seen as an incomplete command by the shell.

Any ideas anyone?

Thanks,
Sven.

Stachu 'Dozzie' K.

2006-11-28, 7:29 am

On 28.11.2006, Sven <sven.holcombe@gmail.com> wrote:
> Hi there,
>
> I'm trying to run awk from the command line using the double-quote ["]
> character as the delimiter.
> When run from my shell, the following command works just fine:
>
> awk -F\" '{print $2}' file.html
>
> However, I am trying to call bash from an external application, so I
> need to wrap the whole command in double-quotes, giving:
>
> bash -c "awk -F\" '{print $2}' Img0003.html"
>
> The above of course gives an error because my delimiting ["] closes the
> bash command. I have tried many combinations of escape-char and
> quote-char (such as "awk -F\\" ..."), but these all seem to either
> error, or are seen as an incomplete command by the shell.
>
> Any ideas anyone?


You need to quote \ character in command as well as " character (you're
using bash -c ".."; all double quotes in double quotes must be, uhm,
quoted independently).

--
<Kosma> Niektórzy lubi± dozziego...
<Kosma> Oczywi¶cie szanujemy ich.
Stanislaw Klekot
Stephane CHAZELAS

2006-11-28, 7:29 am

2006-11-28, 00:14(-08), Sven:
> Hi there,
>
> I'm trying to run awk from the command line using the double-quote ["]
> character as the delimiter.
> When run from my shell, the following command works just fine:
>
> awk -F\" '{print $2}' file.html
>
> However, I am trying to call bash from an external application, so I
> need to wrap the whole command in double-quotes, giving:
>
> bash -c "awk -F\" '{print $2}' Img0003.html"
>
> The above of course gives an error because my delimiting ["] closes the
> bash command. I have tried many combinations of escape-char and
> quote-char (such as "awk -F\\" ..."), but these all seem to either
> error, or are seen as an incomplete command by the shell.

[...]

\" doesn't close the bash command, but opens a quoted string for
the new bash interpreter (and it is unmatched). Furthermore,
your $2 will be expanded by your shell as it is inside double
quotes.

bash -c 'awk -F\" "{print \$2}" Img0003.html'

bash -c "awk -F\\\" '{print \$2}' Img0003.html"

bash -c "awk -F\\\" "{print \\\$2}" Img0003.html"

AWK_SCRIPT='{print $2}' DELIMITER='"' bash -c '
awk -F"$DELIMITER" "$AWK_SCRIPT" Img0003.html"'


--
Stéphane
Sven

2006-11-29, 1:30 am


Stephane CHAZELAS wrote:
> 2006-11-28, 00:14(-08), Sven:
> [...]
>
> \" doesn't close the bash command, but opens a quoted string for
> the new bash interpreter (and it is unmatched). Furthermore,
> your $2 will be expanded by your shell as it is inside double
> quotes.
>
> bash -c 'awk -F\" "{print \$2}" Img0003.html'
>
> bash -c "awk -F\\\" '{print \$2}' Img0003.html"
>
> bash -c "awk -F\\\" "{print \\\$2}" Img0003.html"
>
> AWK_SCRIPT='{print $2}' DELIMITER='"' bash -c '
> awk -F"$DELIMITER" "$AWK_SCRIPT" Img0003.html"'
>


Thanks for that, the second option ran through nicely and it's a bit
clearer to me now where I was going wrong.

Cheers,
Sven.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com