# How to execute run(\`ls \*.pdb\`)?

**URL:** <https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541>\
**Category:** New to Julia\
**Created:** [May 20, 2021, 8:05pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541 "2021-05-20T20:05:01Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 20, 2021, 8:05pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/1 "2021-05-20T20:05:01Z")

</div>

How to run a command like this:

```julia
julia> run(`ls *.pdb`)
ERROR: LoadError: parsing command `ls *.pdb`: special characters "#{}()[]<>|&*?~;" must be quoted in commands

```

and, since we are here, can that that error message be improved? Maybe is my poor english, but adding `"*"`, or `'*'`, or `\*`, does not work, so I do not understand what `must be quoted` means there.

By the way, specifically here I want to get the number of files satisfying `*.pdb`, so I am not even sure if this is the right track, since I noticed now that I cannot automatically get the output of to a variable. Two things to check there.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 20, 2021, 8:19pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/2 "2021-05-20T20:19:02Z")

</div>

Well, I did find this:

```julia
julia> length(filter(f -> f[end-2:end] == "pdb", readdir("./")))
21

```

but perhaps a simpler option exists. (I do not care with performance here, the clearer the better).

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [May 20, 2021, 8:25pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/3 "2021-05-20T20:25:34Z")

</div>

See [https://github.com/vtjnash/Glob.jl](https://github.com/vtjnash/Glob.jl)

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [May 20, 2021, 8:30pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/4 "2021-05-20T20:30:52Z")

</div>

> [@lmiq](#):
>
> can that that error message be improved?

Note that that error is there so we can hopefully implement this in the future.

---

<div class="post-metadata">

**Author:** ![jmert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmert/32/3161_2.png) [@jmert](https://discourse.julialang.org/u/jmert)\
**Post date:** [May 20, 2021, 8:56pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/5 "2021-05-20T20:56:15Z")

</div>

Another (not necessarily better, but sometimes most expedient) option is to just let your shell handle all the things that your shell normally handles:

```julia
julia> run(`sh -c 'ls -1d *'`)
base
cli
contrib
CONTRIBUTING.md
deps
doc
etc
HISTORY.md
julia
LICENSE.md
Makefile
Make.inc
Make.user
NEWS.md
README.md
src
stdlib
sysimage.mk
test
ui
usr
usr-staging
VERSION
Process(`sh -c 'ls -1d *'`, ProcessExited(0))

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 20, 2021, 9:03pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/6 "2021-05-20T21:03:10Z")

</div>

> [@jmert](#):
>
> `julia> run(`sh -c ‘ls -1d \*’`)`

Nice, I like that. How can I get that output into a variable?

---

<div class="post-metadata">

**Author:** ![jmert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmert/32/3161_2.png) [@jmert](https://discourse.julialang.org/u/jmert)\
**Post date:** [May 20, 2021, 9:04pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/7 "2021-05-20T21:04:15Z")

</div>

> [@lmiq](#):
>
> Nice, I like that. How can I get that output into a variable?

Maybe not the best way (I haven’t done a lot of process piping in Julia yet), but something that works is:

```julia
julia> buf = IOBuffer()
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1)

julia> run(pipeline(`sh -c 'ls -1d *'`, stdout=buf))
Process(`sh -c 'ls -1d *'`, ProcessExited(0))

julia> seek(buf, 0)
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=175, maxsize=Inf, ptr=1, mark=-1)

julia> readlines(buf) # or just String(take!(buf)) to get as one String
23-element Vector{String}:
 "base"
 "cli"
 "contrib"
 "CONTRIBUTING.md"
 "deps"
 "doc"
 "etc"
 "HISTORY.md"
 "julia"
 "LICENSE.md"
 "Makefile"
 "Make.inc"
 "Make.user"
 "NEWS.md"
 "README.md"
 "src"
 "stdlib"
 "sysimage.mk"
 "test"
 "ui"
 "usr"
 "usr-staging"
 "VERSION"

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 20, 2021, 9:08pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/8 "2021-05-20T21:08:05Z")

</div>

And the beauty was lost 😂

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [May 20, 2021, 9:08pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/9 "2021-05-20T21:08:43Z")

</div>

You can use `read`, like `read(`sh -c 'ls -1d *'`, String)`

---

<div class="post-metadata">

**Author:** ![jmert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmert/32/3161_2.png) [@jmert](https://discourse.julialang.org/u/jmert)\
**Post date:** [May 20, 2021, 9:08pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/10 "2021-05-20T21:08:50Z")

</div>

> [@jmert](#):
>
> Maybe not the best way

Looks like that wasn’t — `read`-like functions works in several cases:

```julia
julia> readlines(`sh -c 'ls -1d *'`)
23-element Vector{String}:
 "base"
 "cli"
 "contrib"
 "CONTRIBUTING.md"
 "deps"
 "doc"
 "etc"
 "HISTORY.md"
 "julia"
 "LICENSE.md"
 "Makefile"
 "Make.inc"
 "Make.user"
 "NEWS.md"
 "README.md"
 "src"
 "stdlib"
 "sysimage.mk"
 "test"
 "ui"
 "usr"
 "usr-staging"
 "VERSION"

julia> String(read(`sh -c 'ls -1d *'`))
"base\ncli\ncontrib\nCONTRIBUTING.md\ndeps\ndoc\netc\nHISTORY.md\njulia\nLICENSE.md\nMakefile\nMake.inc\nMake.user\nNEWS.md\nREADME.md\nsrc\nstdlib\nsysimage.mk\ntest\nui\nusr\nusr-staging\nVERSION\n"

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 20, 2021, 9:10pm UTC](https://discourse.julialang.org/t/how-to-execute-run-ls-pdb/61541/11 "2021-05-20T21:10:29Z")

</div>

Now we are talking! Thank you all! 🙂
