[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] The best way to get a file in a directory
From: |
Dennis Williamson |
Subject: |
Re: [Help-bash] The best way to get a file in a directory |
Date: |
Thu, 22 Nov 2018 17:20:03 -0600 |
On Thu, Nov 22, 2018, 4:31 PM Peng Yu <address@hidden wrote:
>
>> https://unix.stackexchange.com/a/62883
>>
>
> This involves find. Anything native to bash that can return an arbitrary
> file?
>
>> <https://unix.stackexchange.com/a/62883>
>>
> <https://unix.stackexchange.com/a/62883>
>>
> --
> Regards,
> Peng
>
# find the first file in a directory
shopt -s nullglob
for file in dir/*
do
if [[ -f $file ]] # skip subdirs
then
break
fi
done
if [[ -n $file ]]
then
echo "Found $file"
fi
If you tell us what you're really trying to do we may be able to offer
better suggestions.
Re: [Help-bash] The best way to get a file in a directory, Chris F.A. Johnson, 2018/11/29