?(pattern-list) Optionally matches any one of the given
patterns.
*(pattern-list) Matches zero or more occurrences of the given
patterns.
+(pattern-list) Matches one or more occurrences of the given
patterns.
@(pattern-list) Matches exactly one of the given patterns.
!(pattern-list) Matches anything, except one of the given
patterns.
The key point that rveri seems to be missing is that the shell uses filename pattern matching (not regular expressions) when expanding the arguments that will be passed to ls. Although there are some similarities between pattern matching and regular expression, many of the details are different.
Thanks,Scrutinizer, Corona, Yoda First 3 worked.. to list all files NOT starting with a :
# Worked well: Seems matching is passed to ls command: " ls -l [!a]bc "
# ls -l ab[c]
-rw------- 1 useradm users 0 Mar 27 12:57 abc
# ls -l [!a]bc
-rw------- 1 useradm users 0 Mar 26 15:27 bbc
# Worked well: Seems matching is passed to shell.
# echo [!a]bc
bbc
This is too worked fine, seems matching is done through shell.
# ls -l !(a)+(bc)
-rw------- 1 useradm users 0 Mar 26 15:27 bbc
-rw------- 1 useradm users 0 Mar 26 15:27 bbcabc
-rw------- 1 useradm users 0 Mar 26 15:27 bbcbbc
#
Yoda, thanks for the manual page,
Don thanks for pointing out the difference of use when "shell uses filename pattern matching" & when "Regular expression uses pattern matching".
Is there a way we can figure out which is shell doing, and which is doing by regular expressions.
For example with the below example: How to figure out which portion is shell or regex performing the operation:
# ls -l bbcbbc
-rw------- 1 useradm users 0 Mar 26 15:27 bbcbbc
# ls -l !([c-z])?[c][b-d]
-rw------- 1 useradm users 0 Mar 26 15:27 bbcbbc
echo $SHELL
/usr/bin/ksh
#OS= hp-ux 11.23
In general, the answer is to read the man pages. But as a high altitude first cut, any unquoted argument passed to the shell that is not a parameter expansion (i.e., $name or ${...name...} that is not part of a shell command lanuage construct (e.g., if , then , else , fi , case , esac , ...) will be subject to pathname expansion.