This really sounds simple but I can't think of a neat way of doing it, I want to test (in bash) if there's any file with a specific suffix in a particular directory.
This means I can't use "[ -f <filename> ]" because I don't know the filename and I don't see how I can use "[ *.sfx ]" because if there are no *.sfx files the string is still not empty.
I suppose I could say something like "[ *.sfx = '*.sfx' ]" but it's a quoting nightmare.
Any better ideas?
On 9 July 2014 17:11, Chris Green cl@isbd.net wrote:
This really sounds simple but I can't think of a neat way of doing it, I want to test (in bash) if there's any file with a specific suffix in a particular directory.
Print the filenames in the directory and grep for the suffix at the end of the line?
Or write a C program to do it? That way, you could re-use that whenever you need to write a similar script.
Regards, Srdjan
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
On 09/07, Chris Green wrote:
This really sounds simple but I can't think of a neat way of doing it, I want to test (in bash) if there's any file with a specific suffix in a particular directory.
I suppose you could use ls
ls gl*b &>/dev/null && echo Yes || echo No
seems to work
Steve
Use Python
import os import fnmatch for f in fnmatch.filter(os.listdir(os.curdir),'*.sfx'): print f
On 9 July 2014 17:11, Chris Green cl@isbd.net wrote:
This really sounds simple but I can't think of a neat way of doing it, I want to test (in bash) if there's any file with a specific suffix in a particular directory.
This means I can't use "[ -f <filename> ]" because I don't know the filename and I don't see how I can use "[ *.sfx ]" because if there are no *.sfx files the string is still not empty.
I suppose I could say something like "[ *.sfx = '*.sfx' ]" but it's a quoting nightmare.
Any better ideas?
-- Chris Green
main@lists.alug.org.uk http://www.alug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!