[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Suppress a "No such file” message when using the ls command
From: |
Reuti |
Subject: |
Re: Suppress a "No such file” message when using the ls command |
Date: |
Mon, 30 Mar 2020 19:34:50 +0200 |
Hi,
> Am 30.03.2020 um 19:28 schrieb Richard Taubo <address@hidden>:
>
> Hi!
>
> Trying to get the last pdf file in a directory and suppress a “No such file”
> message when a pdf file does not exist.
> This works in zsh:
> my_last_file=$(/bin/ls -t *.pdf | head -1) 2> /dev/null
>
> The same command returns a “No such file or directory” in bash when now pdf
> files are found.
>
> I get this to work though, but that will require more steps:
> my_last_file=$(/bin/ls -t *.pdf 2> /dev/null)
Using:
$ shopt -s nullglob
will prevent that a plain "*.pdf" is returned in case no match is found when
applying the wildcard.
-- Reuti