1

The command fails via bash -c:

bash -c 'sudo lspci -vvv | awk \'/System peripheral/ {portn=$1} /Status:/ {split($3,a,"M");printf "%s\n",a[1]}\''

-bash: syntax error near unexpected token `('

The same command works well if is run directly in the console sudo lspci -vvv | awk '/System peripheral/ {portn=$1} /Status:/ {split($3,a,"M");printf "%s\n",a[1]}'

How to cover '(' in the command string for bash -c ?

minskster
  • 512
  • 3
  • 6

1 Answers1

3

You cannot escape single quotes inside single quotes that way. It does not work.

Your command is being seen as

sudo lspci -vvv | awk /System peripheral/ {portn=$1} /Status:/ {split($3,a,"M");printf "%s\n",a[1]}

which fails.

To place a single quote inside a single quoted string you need to use '\''.

So your command becomes:

bash -c 'sudo lspci -vvv | awk '\''/System peripheral/ {portn=$1} /Status:/ {split($3,a,"M");printf "%s\n",a[1]}'\'
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148