You are not logged in.

#1 2009-03-10 19:50:41

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 185

Why won't `bash -c "echo 1 2 3 | awk '{print $1}'"' print `1'?[SOLVED]

Why doesn't `bash -c "echo 1 2 3 | awk '{print $1}'"' print `1' instead of `1 2 3'?  It seems to be a bug in `awk', because running `bash -c "echo 1 2 3 | sed -e 's|1|5|'"' prints `5 2 3'.

Last edited by deltaecho (2009-03-10 20:20:01)


Dylon

Offline

#2 2009-03-10 19:54:58

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: Why won't `bash -c "echo 1 2 3 | awk '{print $1}'"' print `1'?[SOLVED]

I'm not sure if it's a awk bug:

echo 1 2 3 | awk '{print $1}'
1
zsh -c "echo 1 2 3 | awk '{print $1}'"
1 2 3

(lambda ())

Offline

#3 2009-03-10 19:55:38

abesto
Member
From: Hungary
Registered: 2009-03-05
Posts: 49
Website

Re: Why won't `bash -c "echo 1 2 3 | awk '{print $1}'"' print `1'?[SOLVED]

umm...

abesto ~  $  echo 1 2 3 | awk '{print $1}'
1

It's fine here. I don't think the problem is with awk.

Last edited by abesto (2009-03-10 19:56:25)


Linux user #476135 || Dotfiles hosted by GitHub

Offline

#4 2009-03-10 19:57:31

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 185

Re: Why won't `bash -c "echo 1 2 3 | awk '{print $1}'"' print `1'?[SOLVED]

Running

$ echo 1 2 3 | awk '{print $1}'

does work, but running

$ bash -c "echo 1 2 3 | awk '{print $1}'"

does not.


Dylon

Offline

#5 2009-03-10 20:16:08

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Why won't `bash -c "echo 1 2 3 | awk '{print $1}'"' print `1'?[SOLVED]

The $1 is interpreted as an empty string, even though it is in single quotes, so you are running echo 1 2 3 | awk '{print }'

Instead try this:
$ bash -c "echo 1 2 3 | awk '{print \$1}'"
1

Also see bash -x -c

--> bash -x -c "echo 1 2 3 | awk '{print $1}'"
+ echo 1 2 3
+ awk '{print }'
1 2 3
--> bash -x -c 'echo 1 2 3 | awk "{print $1}"'
+ echo 1 2 3
+ awk '{print }'
1 2 3
--> bash -x -c "echo 1 2 3 | awk '{print \$1}'"
+ awk '{print $1}'
+ echo 1 2 3
1

Offline

#6 2009-03-10 20:18:25

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 185

Re: Why won't `bash -c "echo 1 2 3 | awk '{print $1}'"' print `1'?[SOLVED]

Procyon wrote:

The $1 is interpreted as an empty string, even though it is in single quotes, so you are running echo 1 2 3 | awk '{print }'

Instead try this:
$ bash -c "echo 1 2 3 | awk '{print \$1}'"
1

Also see bash -x -c

--> bash -x -c "echo 1 2 3 | awk '{print $1}'"
+ echo 1 2 3
+ awk '{print }'
1 2 3
--> bash -x -c 'echo 1 2 3 | awk "{print $1}"'
+ echo 1 2 3
+ awk '{print }'
1 2 3
--> bash -x -c "echo 1 2 3 | awk '{print \$1}'"
+ awk '{print $1}'
+ echo 1 2 3
1

That works! Thanks @Procyon!


Dylon

Offline

Board footer

Powered by FluxBB