# Is there a package that introduces shell-like syntax using macros and the builtin pipeline?

**URL:** <https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639>\
**Category:** General Usage\
**Created:** [August 9, 2020, 8:15pm UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639 "2020-08-09T20:15:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [August 9, 2020, 8:15pm UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639/1 "2020-08-09T20:15:21Z")

</div>

I am thinking of changing my primary script language to Julia. The `pipeline` and backtick command construction are awesome, but their syntax is not as simple and concise as traditional shells. Is there a package dedicated to introducing syntactic sugar around scripting usage? Something like:

```julia
@s cat "somedir/somefile.txt" | head -n 23 | tail -n 10 | grep julia_var > "result.txt"

```

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [August 9, 2020, 8:24pm UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639/2 "2020-08-09T20:24:06Z")

</div>

There are several packages that provide additional support for piping, most of which are enumerated here: [https://github.com/JuliaLang/julia/issues/5571#issuecomment-205754539](https://github.com/JuliaLang/julia/issues/5571#issuecomment-205754539)

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [August 9, 2020, 8:35pm UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639/3 "2020-08-09T20:35:24Z")

</div>

Yes, those are awesome, and I already use them. But they are for function chaining inside Julia. I want traditional shell piping that chains external processes. It doesn’t seem one exists though. I should write one when I get the time.

---

<div class="post-metadata">

**Author:** ![waldyrious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/waldyrious/32/80_2.png) [@waldyrious](https://discourse.julialang.org/u/waldyrious)\
**Post date:** [August 9, 2020, 9:33pm UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639/4 "2020-08-09T21:33:14Z")

</div>

I assume you’re aware of these, but for discoverability and future reference I thought it would be worth mentioning some useful related resources:

- [Shelling Out Sucks](https://julialang.org/blog/2012/03/shelling-out-sucks/)
- [Put This In Your Pipe](https://julialang.org/blog/2013/04/put-this-in-your-pipe/)
- [Running Shell Commands from Julia | Leah Hanson](http://blog.leahhanson.us/post/julia/julia-commands.html)

Also, for REPL usage, there’s the [shell mode](https://docs.julialang.org/en/v1/stdlib/REPL/#man-shell-mode-1).

---

<div class="post-metadata">

**Author:** ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)\
**Post date:** [August 9, 2020, 9:38pm UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639/5 "2020-08-09T21:38:47Z")

</div>

> [@NightMachinary](#):
>
> But they are for function chaining inside Julia. I want traditional shell piping that chains external processes.

Aren’t “external processes” also represented as a function or some other callable object? What prevents them from being piped?

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [August 9, 2020, 10:07pm UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639/6 "2020-08-09T22:07:50Z")

</div>

If someone writes a wrapper around them, then yes, any external program can be turned into a Julia callable. In Python, there is `from plumbum.cmd import cat`, which autowraps external programs. I am not aware of such tools in Julia.

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [August 9, 2020, 10:16pm UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639/7 "2020-08-09T22:16:59Z")

</div>

`run(`echo hello, world` |> "test.txt")` doesn’t work for me:

```julia
ERROR: MethodError: objects of type String are not callable
Stacktrace:
 [1] |>(::Cmd, ::String) at ./operators.jl:823
 [2] top-level scope at REPL[96]:1

```

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [August 9, 2020, 11:33pm UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639/8 "2020-08-09T23:33:18Z")

</div>

```julia
run(pipeline(`echo hello, world`, stdout = "test1.txt"))`

```

according to the docs on [external commands](https://docs.julialang.org/en/v1/manual/running-external-programs/#Running-External-Programs-1)

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [August 9, 2020, 11:38pm UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639/9 "2020-08-09T23:38:05Z")

</div>

I know, I am looking for syntactic sugar around these builtins.

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [August 10, 2020, 2:38am UTC](https://discourse.julialang.org/t/is-there-a-package-that-introduces-shell-like-syntax-using-macros-and-the-builtin-pipeline/44639/10 "2020-08-10T02:38:06Z")

</div>

```julia
# → is \to<tab>

julia> →(args...) = pipeline(args...)

julia> run(`cat /etc/passwd` → `head -4` → `sort`)

julia> run(`cat "somedir/somefile.txt"` → `head -n 23` → `tail -n 10` → pipeline(`grep julia_var`,stdout="result.txt") )

```
