delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/01/08/10:40:53

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:date:message-id:references
:mime-version:content-type:content-transfer-encoding; q=dns; s=
default; b=R7Q7oA6ihUBCpUq6eO+wAiph0G+9zsJnXahNNdQjFo605OiXitTHA
rOOy4ZjzBjnGBtSsWuiEp92twnLcV4J9hNXQMstb6as0QYNtCnI77ZVrWdEzXEB4
L0SZo1cuNAphpIZ3mGGvgc6rLCY+FsoqFezPnoY3g4j5nt9My/azzg=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:date:message-id:references
:mime-version:content-type:content-transfer-encoding; s=default;
bh=Bd2RwiifdT19Wav/AVwQ2/Tdluk=; b=LuOki4TablIDItBpCzdDO8IMiDJK
O7sZBz2282T1RiRpj50W9FVtjuQ6OZJ2chIj3uwr1hwsHqbyv0xwQ25kSKwjE/0m
L/ozCd8vwXU4fQ+cVClcBjxWE4YuDBr+h/c1n6nhSaIy9nIhtg5vUFAYjxVkoHXj
1gibA1tBQenKAQk=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2
X-HELO: plane.gmane.org
To: cygwin AT cygwin DOT com
From: Paul <Paul DOT Domaskis AT gmail DOT com>
Subject: Re: Force "ls" to show .exe extension
Date: Thu, 8 Jan 2015 15:38:30 +0000 (UTC)
Lines: 86
Message-ID: <loom.20150108T163702-321@post.gmane.org>
References: <loom DOT 20150106T203355-631 AT post DOT gmane DOT org> <1941710256 DOT 20150107013212 AT yandex DOT ru> <loom DOT 20150107T010713-891 AT post DOT gmane DOT org> <6CF2FC1279D0844C9357664DC5A08BA20FA979B4 AT msgb09 DOT nih DOT gov> <loom DOT 20150107T164855-744 AT post DOT gmane DOT org> <D0D2B422.8725%bob_mcgowan AT symantec DOT com>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes

Bob McGowan <Bob_McGowan <at> symantec.com> writes:
| Back to Paul's problem, getting a list of the actual filenames, as
| they actually exist in the filesystem, can be handled by 'find', I
| think.  At least it worked in my simple test setup, above.
| 
| $ find . -name abc
| ./abc
| $ find . -name 'abc*'
| ./abc
| ./abc.bat
| ./abc.exe
| ./abc.sh
| 
| Since find prints each file name on a line by itself, filenames with
| spaces just "work":
| 
| $ touch 'pdq xyz'
| $ find .
| .
| ./abc
| ./abc.bat
| ./abc.exe
| ./abc.sh
| ./pdq xyz
| 
| To process the above output, use a 'while' loop with the 'read'
| command and quote the shell variable in the loop body to preserve
| the single filename with spaces:
| 
| $ find . |
| > while read filenames
| > do
| >  file "$filenames"
| > done
| .: directory
| ./abc: empty
| ./abc.bat: empty
| ./abc.exe: empty
| ./abc.sh: empty
| ./pdq xyz: empty
| 
| The above is for illustration only.  It is not efficient, since
| 'file' is run 6 times, when it could have run once with multiple
| file names, but then the quoting wouild be more difficult.  You
| would replace it with 'ls -l' to get individual file metadata,
| though again it would be inefficient.
| 
| Using 'xargs' would improve this, assuming the right parameters are
| used.  This will work with 'xargs' and 'cpio', I'm not sure which
| other commands might support literal NULL termination of strings
| (note the 0 (zero) in each command's args).
| 
| find . -print0 | xargs -0 file
| .: directory
| ./abc: empty
| ./abc.bat: empty
| ./abc.exe: empty
| ./abc.sh: empty
| ./pdq xyz: empty

It certainly is educational.  For the original problem, though, I'd
like to keep it simple enough to fit into one line.  It has to accept
output from "type" and must allow for "ls -l" and/or "ls -ltd" (or the
like):

   $ls -d `type -pa pdfcrop | sed -e 's/.*/&*/'`

      /bin/pdfcrop@  /home/User.Name/bin/pdfcrop.exe*
      /usr/bin/pdfcrop@

   $ls -ld `type -pa pdfcrop | sed -e 's/.*/&*/'`

      lrwxrwxrwx 1 User.Name Domain Users 48 Nov 10 16:35 /bin/pdfcrop
      -> /usr/share/texmf-dist/scripts/pdfcrop/pdfcrop.pl*

      -rwx------+ 1 User.Name Domain Users 33792 Jun 21 2013
      /home/User.Name/bin/pdfcrop.exe*

      lrwxrwxrwx 1 User.Name Domain Users 48 Nov 10 16:35
      /usr/bin/pdfcrop ->
      /usr/share/texmf-dist/scripts/pdfcrop/pdfcrop.pl*

I don't like using the back ticks myself because of its atrocious
readability, but I'm not religious about it.

P.S. Gotta luv the gmane captcha words.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019