Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell wildcards don't work on Julia's shell mode

Tags:

shell

julia

When running IPython I can run any shell command with an exclamation mark in front it:

In [1]: !ls
file1  file2  file3  file4

In [2]: !ls file*
file1  file2  file3  file4

However, some things (in particular the use if wildcards) don't work on the Julia REPL in shell mode (after you type in the semicolon):

shell> ls file
file1 file4  file2  file3
shell> ls file*
ls: cannot access 'file*': No such file or directory

Am I missing something here? Is there a way to get wildcards to behave as they do normally in a Linux shell?

like image 423
TomCho Avatar asked Mar 02 '21 01:03

TomCho


1 Answers

You're right, the Julia shell REPL mode is not a shell in the sense most people expect, some discussion can be found here and here. Currently, the arguments are passed as is, with no shell expansion so if the program supports a literal '*' that works fine:

shell> find -iname *
.
./file1
./file2
./file3
./file4

If it doesn't you need to figure out another way. Like calling through bash:

shell> bash -c 'ls *'
file1  file2  file3  file4

Or using Julia functions/macros:

julia> bash(str::String) = run(`bash -c $str`)
bash (generic function with 1 method)

julia> macro sh_str(str::String)
       bash(str)
       end

julia> sh"ls *"
file1  file2  file3  file4
Process(`bash -c 'ls *'`, ProcessExited(0))
like image 83
ahnlabb Avatar answered Oct 17 '22 04:10

ahnlabb