[NTLUG:Discuss] How to get mv to not report when there are no files?
Fred James
fredjame at fredjame.cnc.net
Tue Nov 6 23:56:31 CST 2007
Leroy Tennison wrote:
(omissions for brevity)
>if [ -f /home/johnc/* ]; then ...
>
>but fortunately I tested before I did. The best I could come up with
>quickly was
>
>for i in /home/johnc/*; do if [ -f "$i" ] mv ...
>
>which leads to the question "Is there no wildcard file existence test in
>bash?"
>
>
Leroy Tennision
...not sure this is answering your question...in the bit of script
below, the first test looks at the current working directory in which
are found the script and a directory called 'none' which contains
nothing; the second test is used to report on files only (avoiding
directories); the third test looks inside the directory called
'none'...and from running this script, one might surmise that:
(1) "if test -f" (first test) is all that is needed to see if there are
any regular files in the current working directory
(2) "if test -f ./none" (third test) (or similar form) is all that is
needed to see if there are any regular files in some other directory
Hope this helps - is that what you were asking?
Regards
Fred James
#! /bin/bash
#
if test -f
then
pwd
for i in `ls`
do
if test -f $i
then
echo $i
fi
done
else
echo "None here"
fi
echo "`pwd`/none"
if test -f ./none
then
for i in `ls ./none/*`
do
echo $i
done
else
echo "None here"
fi
exit
More information about the Discuss
mailing list