# Escaping properly a bash command

**URL:** <https://discourse.julialang.org/t/escaping-properly-a-bash-command/81316>\
**Category:** General Usage\
**Tags:** question, cmd\
**Created:** [May 19, 2022, 4:26pm UTC](https://discourse.julialang.org/t/escaping-properly-a-bash-command/81316 "2022-05-19T16:26:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Post date:** [May 19, 2022, 4:26pm UTC](https://discourse.julialang.org/t/escaping-properly-a-bash-command/81316/1 "2022-05-19T16:26:23Z")

</div>

I am trying to execute a command which has its own variable.  
Specifically, I am trying to submit jobs on a cluster using

```julia
Njobs = 10
for r in res
    submit = `bsub -R 'rusage[mem=800]' -J jobname\[1-$Njobs\] julia_script.jl $r \${LSB_JOBINDEX}`
    run(submit)
end

```

(Taken from [DrWatson’s suggestions](https://juliadynamics.github.io/DrWatson.jl/dev/real_world/#Using-a-Serial-Cluster-1)).

The problem is that I want the cluster to get the parameter `LSB_JOBINDEX` and put a serial number going from 1 to `Njobs`. But if I use `'` escaping around `$LSB_JOBINDEX` then it simply passes the string `$LSB_JOBINDEX`.  
If I do not use escaping, I get an error.

How can I solve this issue?

---

<div class="post-metadata">

**Author:** ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Post date:** [May 19, 2022, 5:00pm UTC](https://discourse.julialang.org/t/escaping-properly-a-bash-command/81316/2 "2022-05-19T17:00:20Z")

</div>

I figured it out:

```julia
Njobs = 10
for r in res
    bsub_cmd = "julia julia_script.jl $r \${LSB_JOBINDEX}"
    submit = `bsub -R 'rusage[mem=800]' -J jobname\[1-$Njobs\] "$bsub_cmd"`
    run(submit)
end

```
