I am trying to find the path of a daemon using which command by the following in a ksh shell script
But if the daemon is not present it gives a warning in the format..
no DaemonName .....bla bla bla
But since I cannot display that directly, I currently do this
tmp=`which daemonName`
tmp2=`which daemonName | grep "no DaemonName"`
if [[ "$tmp2" != "" ]]
tmp=wrong name
How can I do the same in a simple single line?
What I really want is that if the daemon is not there, It should give a default string, while if present it should give the which commands output.
This will set the tmp variable like you want it:
Edit: One issue with this suggestion is the
whichcommand behavior isn’t standardized, as the AIX odd implementation demonstrates.As you use
ksh, a simple workaround is to substitute thewhichcommand by thewhencebuiltin: