help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Suppress a "No such file” message when using the ls command


From: Richard Taubo
Subject: Suppress a "No such file” message when using the ls command
Date: Mon, 30 Mar 2020 19:28:09 +0200

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


reply via email to

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