# Error assigning bash command's output to variable with Julia

**URL:** <https://discourse.julialang.org/t/error-assigning-bash-commands-output-to-variable-with-julia/27389>\
**Category:** New to Julia\
**Created:** [August 10, 2019, 12:42pm UTC](https://discourse.julialang.org/t/error-assigning-bash-commands-output-to-variable-with-julia/27389 "2019-08-10T12:42:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [August 10, 2019, 12:42pm UTC](https://discourse.julialang.org/t/error-assigning-bash-commands-output-to-variable-with-julia/27389/1 "2019-08-10T12:42:51Z")

</div>

I would like to run a bash command called samtools and assign its output to a variable that I can process with julia. Thus I made:

```julia
julia> r_file
"A3-T_F-AlnSrtDed.bam"
julia> r_locus
"chrV:254748988-254749089"
julia> query = run(pipeline(`samtools ... $r_file $r_locus`,
                       `grep -v @`, `cut -f 5`), String)
ERROR: MethodError: no method matching spawn_opts_inherit(::Type{String})
Closest candidates are:
  spawn_opts_inherit() at process.jl:545
  spawn_opts_inherit(::Tuple{Union{RawFD, FileRedirect, IO},Union{RawFD, FileRedirect, IO},Union{RawFD, FileRedirect, IO}}) at process.jl:541
  spawn_opts_inherit(::Union{RawFD, FileRedirect, IO}) at process.jl:545
  ...
Stacktrace:
 [1] #run#503(::Bool, ::Function, ::Base.OrCmds, ::Type) at ./process.jl:662
 [2] run(::Base.OrCmds, ::Type) at ./process.jl:661
 [3] top-level scope at none:0

julia> query = run(pipeline(`samtools ... $r_file $r_locus`, 
   `grep -v @`, `cut -f 5`))
21
Base.ProcessChain(Base.Process[Process(`samtools ... A3-T_F-AlnSrtDed.bam chrV:254748988-254749089`, ProcessExited(0)), Process(`grep -v @`, ProcessExited(0)), Process(`cut -f 5`, ProcessExited(0))], RawFD(0x00000000), RawFD(0x00000001), RawFD(0x00000002))

```

Essentially, if I don’t use `String`, the command is assigned to `query` but without `String` I get an error.

What is the correct way to assign the shell’s output to a variable? This should be either a string (if there is a single output) or an array.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [August 10, 2019, 3:14pm UTC](https://discourse.julialang.org/t/error-assigning-bash-commands-output-to-variable-with-julia/27389/2 "2019-08-10T15:14:56Z")

</div>

Are you looking for:

```julia
query = read(pipeline(`samtools ... $r_file $r_locus`,
                       `grep -v @`, `cut -f 5`), String)

```

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [August 12, 2019, 8:04am UTC](https://discourse.julialang.org/t/error-assigning-bash-commands-output-to-variable-with-julia/27389/3 "2019-08-12T08:04:23Z")

</div>

Yes I am, thank you
