[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: |
Chet Ramey |
Subject: |
Re: Suppress a "No such file” message when using the ls command |
Date: |
Mon, 30 Mar 2020 16:52:35 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
On 3/30/20 2:22 PM, Richard Taubo wrote:
> Like I said, was thinking about going with the following in bash as that
> worked:
> my_last_file=$(/bin/ls -t *.pdf 2> /dev/null)
The basic rule of thumb is to attach the redirection to the command whose
output you want to redirect (or suppress, as it were). That will keep you
from having to remember that a simple command's word expansions are
performed before any redirections (as posix allows when there are no words
after expanding the words that are not assignments or redirections).
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU address@hidden http://tiswww.cwru.edu/~chet/