Thanks so much for your prompt advise. I tested two commands. They are all work very well. I will use them. I chnaged my shell from
#!/bin/ksh to #!/bin/bash
My question remaining is, after I check and chnage my shell in script. It is Oracle Linux 5. So shell is bash shell. I used original script to test. it return this error code:
./script.sh: command substitution: line 13: syntax error near unexpected token `|'
It is pointed to the same error as begining. Why shell flavor has big difference?
The big flavor difference is: you are depending on what is called undefined behavior.
POSIX standards no not say what happens with nested backtics, for example. So some nice guy who wrote shellA allows it to work correctly (correctly == your expectations, not really required to work). The evil guy who wrote shellB did not do that. He literally follows the standard