-   Linux - General (
-   -   Do not show ls error in bash script (

Rindert 08-18-2006 05:04 PM

Do not show ls error in bash script

I've just started writing my own basg script so i;m kinda new to this all.
My script is going though some directories using a while loop.
In the llop i do an ls command but in some direcotries it gives back an error. That is just becuase there are no file matching the pattern (no files at all.

How can you supprees those errors? The errors mess up all my echo commands because i use echo -n some times.

This i a small example:

  # Make the dir list to go trough
  find -print0 | \
  xargs -0 file | \
  grep ' directory' | \
  cut -f 1 -d : | \
  cut -c 3- | \
  while read cat_dir ; do
    # Aanmaken van het profiel
    cat_profile=`ls -1 *001.jpg | rev | cut -c 8- | rev`
    # morescript......

Matir 08-18-2006 05:22 PM

Try adding '2>/dev/null' on the end of offending commands. This redirects errors to /dev/null rather than output.

Rindert 08-18-2006 05:28 PM

Thanks for your quick reply :D

All times are GMT -5. The time now is 06:39 AM.