문제

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 '.
도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top