extglob negation not working as expected

Sergiy Kolodyazhnyy

I was trying to use negation to exclude directories from globbing, but directories still appear in pattern match:

bash-4.3$ ls
file_1.txt  testdir
bash-4.3$ shopt extglob
extglob         on
bash-4.3$ echo !(*/)
file_1.txt testdir
bash-4.3$ 

What exactly am I doing wrong ?

Note:I know I can use for loop with [ or find command, but I'm trying to figure out extglob specifically.

Stéphane Chazelas

You can't have a / in the @(...), !(...), *(...)...

The / can only appear between globs, even a[x/y]b is treated as @(a\[x)/@(y\]b). globs are first split on / and each part matched against the content of a directory. When there are x(...) ksh glob extensions, however, there's no splitting on the / that are inside the (...), but each glob part is still matched against file names. In !(*/*), */* is matched against each file name in the current directory. Obviously, no file name may ever contain a /, so it matches nothing, so !(*/*) matches every file.

Here, you'd want to use zsh and its glob qualifiers:

echo *(^/)

For the files of any type except directory. Or to be the opposite of bash's */ (which is any file of type directory after symlink resolution):

echo *(-^/)

(files that are neither directories nor symlinks to directories).

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

AJAX call is not working as expected

分類Dev

jQuery .when().then() not working as expected

分類Dev

.vimrc file not working as expected

分類Dev

*ngIf not working as expected with observable

分類Dev

ItemIsAutoTristate flag not working as expected

分類Dev

KeyboardAvoidingView not working as expected on IOS

分類Dev

PowerShell variables not working as expected

分類Dev

XPath logical 'and' not working as expected?

分類Dev

CancellationTokenSource not working as expected on a TaskCompletionSource

分類Dev

string formatting not working as expected

分類Dev

Why is .on() Not working as expected in jquery?

分類Dev

Tuples in Scala not working as expected

分類Dev

strpos() not working as expected

分類Dev

PHP Dateformat not working as expected

分類Dev

Update not working as expected

分類Dev

ifelse not working as expected in R

分類Dev

$("#form").submit(); is not working as expected

分類Dev

Prototype is not working as expected

分類Dev

LIKE and Equals not working as expected

分類Dev

Regex is not working as expected in javascript

分類Dev

angularjs service not working as expected

分類Dev

NSTask not working as expected / hoped for

分類Dev

Routing not working as expected in CodeIgniter

分類Dev

mhddfs not working as expected

分類Dev

Python: If...and... not working as expected

分類Dev

timeout for ngShow not working as expected

分類Dev

LIKE query not working as expected

分類Dev

boostrap clearfix not working as expected

分類Dev

AltBeacon: ranging not working as expected