#!/bin/bash # number of expected arguments EXPECTED_ARGS=1 # exit value if the number of arguments is wrong E_BADARGS=1 if [ $# -ne $EXPECTED_ARGS ] then echo "Usage: `basename $0` {arg}" exit $E_BADARGS fi if [ ! -e $1 ] then echo "file $1 does not exist" exit $E_BADARGS fi for myfile in $1/* do if [ -d "$myfile" ] then echo "$myfile (DIR)" elif [ -f "$myfile" ] then echo "$myfile" fi done I'm new to bash and I cannot figure out what ! means in if[ ! -e $1] and what $1/* means in for myfile in $1/*. So far I've thought about if[! -e $1] as if (not equal to first parameter) (do this).... is this correct? But then what is not equal to first parameter? for myfile in $1/*, I've no idea what this means. Any help?
[is not bash syntax per se -- it's an alias for thetestcommand. Granted, bash has its own built-in version oftest, but it's still run with the same semantics it would have if it were/usr/bin/testor/usr/bin/[being invoked, and it's worth thinking of as a regular command.help test(whereasman testwill give you the documentation for the non-builtin/usr/bin/[).if[is a completely different thing fromif [; the former is going to be looking for a file named, literally,if[if there's no function or alias sharing that name.