0

Whats wrong here? The echo shows the correct syntax. Please help, thank you.


#!/bin/ksh
CMD="su - db2i72 -c 'db2 list utilities'" # or this
CMD="su - db2i72 -c \'db2 list utilities\'" # or this 
CMD="su - db2i72 -c \"db2 list utilities\"" # or this, always the same...

echo $CMD

$CMD

root@server:~ # ./test
su - db2i72 -c 'db2 list utilities'
Unmatched '.
Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
xyn
  • 19
  • 4

1 Answers1

0

Store commands in functions, not variables. You don't have to worry about quoting at all if you use a function.

cmd() {
    su - db2i72 -c 'db2 list utilities'
}

cmd
John Kugelman
  • 349,597
  • 67
  • 533
  • 578