Pregunta

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 '.
¿Fue útil?

Solución

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top