# What would be julia equivalent of this ruby one liner?

**URL:** <https://discourse.julialang.org/t/what-would-be-julia-equivalent-of-this-ruby-one-liner/71596>\
**Category:** New to Julia\
**Created:** [November 16, 2021, 3:55pm UTC](https://discourse.julialang.org/t/what-would-be-julia-equivalent-of-this-ruby-one-liner/71596 "2021-11-16T15:55:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![benibilme](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@benibilme](https://discourse.julialang.org/u/benibilme)\
**Post date:** [November 16, 2021, 3:55pm UTC](https://discourse.julialang.org/t/what-would-be-julia-equivalent-of-this-ruby-one-liner/71596/1 "2021-11-16T15:55:05Z")

</div>

Hello,

I often use following one liner in ruby to see the details of my PATH. What would be the cleanest version of it in julia with less typing.

`ruby -e 'puts ENV["PATH"].split(":").sort'` or longer version  
`ruby -e 'ENV["PATH"].split(":").sort.each { |path| puts path }'`

This one line code basically splits `PATH` environment variable based on `:` which creates a array of strings, sorts it and displays it. I sometimes add `.sort.reverse` reverse call after sort.

My julia version

`julia -e 'foreach(println, split(ENV["PATH"],":") |> sort )'` or  
`julia -e 'foreach(println, sort(split(ENV["PATH"],":")))'`

I do not know if function composition can be used in one line code written on terminal.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [November 16, 2021, 4:03pm UTC](https://discourse.julialang.org/t/what-would-be-julia-equivalent-of-this-ruby-one-liner/71596/2 "2021-11-16T16:03:23Z")

</div>

```julia
julia -e 'println.(sort(split(ENV["PATH"],":")))'

```

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [November 16, 2021, 4:21pm UTC](https://discourse.julialang.org/t/what-would-be-julia-equivalent-of-this-ruby-one-liner/71596/3 "2021-11-16T16:21:52Z")

</div>

If you want to emulate the “chaining-order” (more or less) as in Ruby you can do:

```julia
julia> ENV["PATH"] |> x->split(x, ":") |> x->sort(x) |> x->println.(x);

```

I thought there might be a better way than with anonymous functions, but I can only do slightly shorter:

```julia
julia> ENV["PATH"] |> x->split(x, ":") |> sort |> println

```

It’s good enough to get the info, but slightly different as I couldn’t end with `println.`

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [November 16, 2021, 5:06pm UTC](https://discourse.julialang.org/t/what-would-be-julia-equivalent-of-this-ruby-one-liner/71596/5 "2021-11-16T17:06:25Z")

</div>

FYI: I could do shorter:

```julia
julia> (println ∘ sort ∘ split)(ENV["PATH"], ":")

help?> \circ

```

Note, to get the circle, meaning function composition, from math, you type that, then press TAB. I just recalled this possibility, that I had never used in Julia, and a long time ago in math… and there are more ways even with it, see the help, but again, didn’t get `print.` to work. Maybe it should (bug or to-be-implemented) or already can?

---

<div class="post-metadata">

**Author:** ![benibilme](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@benibilme](https://discourse.julialang.org/u/benibilme)\
**Post date:** [November 16, 2021, 5:22pm UTC](https://discourse.julialang.org/t/what-would-be-julia-equivalent-of-this-ruby-one-liner/71596/6 "2021-11-16T17:22:26Z")

</div>

Unfortunately this code requires julia console. I wonder if there is a way to write symbolic characters in literal way without needing latex symbols which requires julia aware environment.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [November 16, 2021, 5:30pm UTC](https://discourse.julialang.org/t/what-would-be-julia-equivalent-of-this-ruby-one-liner/71596/7 "2021-11-16T17:30:17Z")

</div>

At worst, or maybe easiest, you can copy and paste the unicode character in your shell. Your shell probably supports unicode via hex, e.g. [shell - How do you echo a 4-digit Unicode character in Bash? - Stack Overflow](https://stackoverflow.com/questions/602912/how-do-you-echo-a-4-digit-unicode-character-in-bash)

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [November 16, 2021, 5:43pm UTC](https://discourse.julialang.org/t/what-would-be-julia-equivalent-of-this-ruby-one-liner/71596/8 "2021-11-16T17:43:53Z")

</div>

```julia
julia> foldl(ComposedFunction, (println, sort, split))
println ∘ sort ∘ split

```
