help-bash
[Top][All Lists]
Advanced

[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: Andreas Kusalananda Kähäri
Subject: Re: Suppress a "No such file” message when using the ls command
Date: Mon, 30 Mar 2020 20:05:29 +0200

On Mon, Mar 30, 2020 at 07:28:09PM +0200, Richard Taubo wrote:
> 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)
> 
> Thansk for any input!
> 
> 
> Best regards
> Richard Taubo

Since you have zsh installed, you may use that from bash:

    my_last_file=$(zsh -c 'print -nr -- *.pdf(.Nom[1])')


-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]