On 2013-11-11 23:31, Allan Duncan wrote:
> I want to check for the existence of a file that can have a variable 
> tail portion of its name.
>      if[-f <file> ] doesn't seem to have the ability to do wild cards.
> Can anyone suggest how to achieve this?

You've not quite given enough information, so I'll take a couple of
guesses:

If you know you will only have one file that matches, then you *can* use
test ([) because it'll expand the pattern generated by the wildcard:

mattcen@owen:~$ ls -l
total 0
mattcen@owen:~$ touch file.foo
mattcen@owen:~$ if [ -f file.* ]; then echo exists; else echo doesn\'t exist; fi
exists

Bash supports [[ as well as [. [[ is more powerful, more lenient to
quoting, and in general, recommended as long as you can depend on using
Bash rather than being POSIX compliant. Run 'help [[' for more
information. It also supports regexesm but you probably don't need them
for your use-case.

-- 
Regards,
Matthew Cengia

Attachment: signature.asc
Description: Digital signature

_______________________________________________
luv-main mailing list
[email protected]
http://lists.luv.asn.au/listinfo/luv-main

Reply via email to