Kapil Sethi wrote:

TOPROCESS=`ls -1 sops* | sort | head -n 1`

Now the problem is that if the is no sops* file in the directory the shell script exits with the error.


It shouldn't. ls will put out an error string to standard error stream (which, by default, would be your console, so you'd see the error on the screen), and TOPROCESS will be an empty string. The above assignment statement itself should not cause the shell script to exit. Check if there is some other statement in your shell script that's causing the script to exit.


You can try a couple of other things though:

1) Suppress the ls error:

TOPROCESS=`ls -1 sops* 2> /dev/null | sort | head -1`

(TOPROCESS will be empty if no file is found)

2) Suppress the ls error and add your own custom error string:

TOPROCESS=`ls -1 sops* 2> /dev/null || echo "No File!" | sort | head -1`

(TOPROCESS will be "No File!" if no file is found)


Manish


_______________________________________________ ilugd mailinglist -- [EMAIL PROTECTED] http://frodo.hserus.net/mailman/listinfo/ilugd Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi http://www.mail-archive.com/ilugd@lists.linux-delhi.org/

Reply via email to