murex Shell Docs

Command Reference: g

Glob pattern matching for file system objects (eg *.txt)


Returns a list of files and directories that match a glob pattern.

Output is a JSON list.


g: pattern -> <stdout>

[ <stdin> -> ] @g command pattern [ -> <stdout> ]

!g: pattern -> <stdout>

<stdin> -> g: pattern -> <stdout>

<stdin> -> !g: pattern -> <stdout>


Inline globbing:

cat: @{ g: *.txt }

Writing a JSON array of files to disk:

g: *.txt |> filelist.json

Writing a list of files to disk:

g: *.txt -> format str |> filelist.txt

Checking if a file exists:

if { g: somefile.txt } then {
    # file exists

Checking if a file does not exist:

!if { g: somefile.txt } then {
    # file does not exist

Return all files apart from text files:

!g: *.txt

Auto-globbing (eg for Bash compatibility):

@g ls *.txt

Filtering a file list based on glob matches:

f: +f -> g: *.html

Remove any glob matches from a file list:

f: +f -> !g: *.html


Pattern Reference


Any command prefixed with @g will be auto-globbed. For example, the two following commands will produce the same output:

» ls @{g: *.go}
benchmarks_test.go  defaults_test.go  flags.go  godoc.go  main.go  murex_test.go

» @g ls: *.go
benchmarks_test.go  defaults_test.go  flags.go  godoc.go  main.go  murex_test.go

The rational behind the ugly @g syntax is simply to make one-liners a bit less painful when coming from more traditional POSIX-like shells (eg Bash) where wildcards are automatically expanded. So if you type ls * (for example) then realise you’ve forgotten to subshell, you can just recall the last command with auto-globbing enabled:

@g ^!!

Inverse Matches

If you want to exclude any matches based on wildcards, rather than include them, then you can use the bang prefix. eg

» g: READ*

» !g: *
Error in `!g` (1,1): No data returned.

When Used As A Method

!g first looks for files that match its pattern, then it reads the file list from STDIN. If STDIN contains contents that are not files then !g might not handle those list items correctly. This shouldn’t be an issue with frx in its normal mode because it is only looking for matches however when used as !g any items that are not files will leak through.

This is its designed feature and not a bug. If you wish to remove anything that also isn’t a file then you should first pipe into either g: *, rx: .*, or f +f and then pipe that into !g.

The reason for this behavior is to separate this from !regexp and !match.


See Also

This site's content is rebuilt automatically from murex's source code after each merge to the master branch. Downloadable murex binaries are also built with the website.

Last built on Thu Oct 13 08:08:18 UTC 2022 against commit ed6b6fced6b6fc609f4be93c5d3348695a762facfecf48f.

Current version is 2.11.2200 which has been verified against 16798 tests cases.