file returns 0 when file does not exists. $ file nfsdjsld nfsdjsld: cannot open `nfsdjsld' (No such file or directory) $ echo $? 0 $ man file RETURN CODE file returns 0 on success, and non-zero on error. Reproducible: Always Steps to Reproduce: 1. file nfsdjsld 2. echo $? 3. man file Actual Results: file return code $? = 0 Expected Results: file return code $? = 1 (just like cat etc.) $ emerge --info Portage 2.1.8.3 (default/linux/x86/10.0/desktop/gnome, gcc-4.4.3, glibc-2.11.2-r0, 2.6.35.5 i686) ================================================================= System uname: Linux-2.6.35.5-i686-AMD_Athlon-tm-_XP_2600+-with-gentoo-1.12.13 Timestamp of tree: Thu, 07 Oct 2010 00:45:01 +0000 app-shells/bash: 4.1_p7 dev-java/java-config: 2.1.11 dev-lang/python: 2.6.5-r3, 3.1.2-r4 dev-util/cmake: 2.8.1-r2 sys-apps/baselayout: 1.12.13 sys-apps/sandbox: 2.3-r1 sys-devel/autoconf: 2.13, 2.65-r1 sys-devel/automake: 1.9.6-r3, 1.10.3, 1.11.1 sys-devel/binutils: 2.20.1-r1 sys-devel/gcc: 4.4.3-r2 sys-devel/gcc-config: 1.4.1 sys-devel/libtool: 2.2.10 sys-devel/make: 3.81-r2 virtual/os-headers: 2.6.30-r1 ACCEPT_KEYWORDS="x86" ACCEPT_LICENSE="*" CBUILD="i686-pc-linux-gnu" CFLAGS="-O2 -march=native -pipe" CHOST="i686-pc-linux-gnu" CONFIG_PROTECT="/etc /usr/share/X11/xkb /var/bind /var/lib/hsqldb" CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo" CXXFLAGS="-O2 -march=native -pipe" DISTDIR="/data/linux/gentoo/distfiles" FEATURES="assume-digests distlocks fixpackages metadata-transfer news parallel-fetch protect-owned sandbox sfperms strict unmerge-logs unmerge-orphans userfetch" GENTOO_MIRRORS="http://distfiles.gentoo.org" LANG="en_US.UTF8" LDFLAGS="-Wl,-O1 -Wl,--as-needed" LINGUAS="en en_US en_GB nl de" MAKEOPTS="-j2" PKGDIR="/data/linux/gentoo/packages/amd_athlon-xp" PORTAGE_CONFIGROOT="/" PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages" PORTAGE_TMPDIR="/compile" PORTDIR="/usr/portage" PORTDIR_OVERLAY="/usr/local/portage" SYNC="rsync://rsync.uk.gentoo.org/gentoo-portage" USE="3dnow 3dnowext X a52 aac acl acpi alsa ao apache2 apm berkdb bluetooth branding bzip2 cairo cdr cli consolekit cpudetection cracklib crypt cups cxx dbus dri dts dvb dvd dvdr dvdread eds emboss encode esd evo exif fam ffmpeg firefox flac fortran gdbm gdu gif gimp gmp gnome gnome-keyring gpm gstreamer gtk hal iconv icu imlib ipv6 java jpeg latex lcms ldap libnotify libsamplerate mad mikmod mmx mng modules mozilla mp3 mp4 mpeg mplayer mudflap nautilus ncurses nls nptl nptlonly nsplugin ogg opengl openmp pam pango pcre pdf perl png policykit ppds pppd python qt3support qt4 quicktime readline reflection samba sdl session sndfile sni soundtouch spell sse ssl startup-notification svg sysfs tcpd theora tiff truetype unicode usb v4l v4l2 vcd vhosts vorbis wmf x264 x86 xcb xinerama xml xorg xulrunner xv xvid xvmc zlib" ALSA_CARDS="intel8x0" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user cache dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers ident imagemap include info log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite setenvif so speling status unique_id userdir usertrack vhost_alias" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en en_US en_GB nl de" RUBY_TARGETS="ruby18" SANE_BACKENDS="pixma" USERLAND="GNU" VIDEO_CARDS="vesa fbdev v4l nv nvidia" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" Unset: CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LC_ALL, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
What if you want two files examined: $ file metadata.xml foobar; echo $? metadata.xml: XML document text foobar: cannot open `foobar' (No such file or directory) 0 $ Since apparently file was designed this way, it's not a Gentoo bug. Most shells have their own means to figure out whether a file exists, so this is rather easy to work around.
What about: $ cat no-file && echo OK || echo NOK cat: no-file: No such file or directory NOK $ file no-file && echo OK || echo NOK no-file: cannot open `no-file' (No such file or directory) OK I agree, it's not gentoo's fault, it's a developers bug. I'm not sure why you say "works for me"...
Jeroen, can you please tell me, if "No such file or directory" is not an error, what would be an error? And of course there is an easy workaround, but if a workaround is needed, doesn't that mean this actually _is_ a bug?
Never mind, I contacted the author. According to http://www.opengroup.org/onlinepubs/9699919799/utilities/file.html: If the file named by the file operand does not exist, cannot be read, or the type of the file named by the file operand cannot be determined, this shall not be considered an error that affects the exit status. So, this is not in line with ls, cat, grep, cp, chmod, gzip, gunzip, cut, head, stat, wc, etc. which all return with a non-zero exit status when any of the given files does not exist.