Stephen Gran on 20 Feb 2006 08:50:53 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] bash and if


On Sun, Feb 19, 2006 at 08:09:19PM -0500, Kyle R. Burton said:
> That actually leads to a pretty clean usage of just case:
> 
> cmp -s "$1" "$2"
> 
> case "$?" in
>   0)
>     echo "Files both exist and are the same..."
>   ;;
> 
>   1)
>     echo "Files both exist and are the different."
>   ;;
> 
>   2)
>     echo "One or both of the files do not exist!"
>   ;;
> 
>   *)
>     echo "Hrm, the exit code was: $?, no clause to handle htat..."
>   ;;
> 
> esac
> 
> That easily and explicitly covers all the bases.  Thanks for suggesting
> case, I'll start using that more now that I think of it this way.

The only problem with this approach is that scripts that are set -e will
fail if cmp returns non-zero.  If you aren't running them set -e, then
the code is certainly much cleaner, I agree.
-- 
 --------------------------------------------------------------------------
|  Stephen Gran                  | You know you've landed gear-up when it  |
|  steve@lobefin.net             | takes full power to taxi.               |
|  http://www.lobefin.net/~steve |                                         |
 --------------------------------------------------------------------------

Attachment: signature.asc
Description: Digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug