Hi all,
I have a weird problem.
When i run the below code in SunOS and Linux i get different outputs
====
$ cat tst.ksh
#!/bin/ksh
echo "Abc" > $LOG_FILE
echo "Ret - $?"
=====
In Solaris
$ ./tst.ksh
Abc
Ret - 0
In GNU Linux
$ ./tst.ksh
./tst.ksh[6]: : cannot open
Ret - 1
The variable LOG_FILE is not set in both environments but it works in Solaris but not in GNU Linux.
Please let me know do i need a code change in GNU environment?
thanks.
how does it "work" in Solaris? What does it do? What shell is that, it's terrible!
$ ksh --version
version sh (AT&T Research) 1993-12-28 s+
$ ksh -s <<'__EOF__'
echo "Abc" > $LOG_FILE
echo "Ret - $?"
__EOF__
ksh[1]: : cannot open
Ret - 1
bash does the same thing: bash: line 1: $LOG_FILE: ambiguous redirect
Do you really need to cover the case where LOG_FILE is unset? Perhaps write a wrapper function:
mute@thedoctor:~$ echo "Hello" > "${LOG_FILE:-/dev/null}"
mute@thedoctor:~$ echo $?
0
there, success every time.