# Bash env setup scripts

**URL:** <https://forums.docker.com/t/bash-env-setup-scripts/15092>\
**Category:** General\
**Created:** [June 9, 2016, 5:54pm UTC](https://forums.docker.com/t/bash-env-setup-scripts/15092 "2016-06-09T17:54:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlbtlbtlb](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/tlbtlbtlb/32/11181_2.png) [@tlbtlbtlb](https://forums.docker.com/u/tlbtlbtlb)\
**Post date:** [June 9, 2016, 5:54pm UTC](https://forums.docker.com/t/bash-env-setup-scripts/15092/1 "2016-06-09T17:54:22Z")

</div>

My Dockerfile sets up a package (ros-indigo-desktop-full) which includes environment setup scripts in bash.  
I’d like to incorporate these settings (like ROS\_PATH) into the environment of the container.

`RUN . /opt/ros/indigo/setup.bash` doesn’t work because the script requires bash, not the /bin/sh that Docker uses.

`RUN ["/bin/bash", "-c", "echo '. /opt/ros/indigo/setup.bash' >> /root/.bashrc"]` does what it suggests, but that .bashrc doesn’t get run when I start the container.

What’s the supported way of doing this?

---

<div class="post-metadata">

**Author:** ![dmaze](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@dmaze](https://forums.docker.com/u/dmaze)\
**Post date:** [June 9, 2016, 8:10pm UTC](https://forums.docker.com/t/bash-env-setup-scripts/15092/2 "2016-06-09T20:10:13Z")

</div>

> [@tlbtlbtlb](#):
>
> My Dockerfile sets up a package (ros-indigo-desktop-full) which includes environment setup scripts in bash.  
> I’d like to incorporate these settings (like ROS\_PATH) into the environment of the container.  
> What’s the supported way of doing this?

Write an entrypoint script that looks like

```auto
#!/bin/bash
. /opt/ros/indigo/setup.bash
exec "$@"

```

Make sure to `COPY` that file into your container and make it executable, and then name it as the `ENTRYPOINT` of your container.

> [@](#):
>
> `RUN . /opt/ros/indigo/setup.bash` doesn’t work because the script requires bash, not the /bin/sh that Docker uses.

Can you fix the script to only use portable POSIX shell features? In my experience these are usually gratuitous syntax differences (`source` instead of the standard `.`, an unnecessary `function` keyword), or are using features that suggest a more powerful language is called for.

Also in the name of technical correctness, Docker doesn’t use any shell at all, or require containers to have shells. If you’re using a container with a Debian or Ubuntu base, those distributions include a lighter-weight, standards-conforming shell as their `/bin/sh`.

---

<div class="post-metadata">

**Author:** ![tlbtlbtlb](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/tlbtlbtlb/32/11181_2.png) [@tlbtlbtlb](https://forums.docker.com/u/tlbtlbtlb)\
**Post date:** [June 10, 2016, 4:53pm UTC](https://forums.docker.com/t/bash-env-setup-scripts/15092/3 "2016-06-10T16:53:54Z")

</div>

The env setup script invokes a tangle of Catkin scripts (the world’s second most overcomplicated build system, after Bower) so it’s hard to fix.

Your ENTRYPOINT solution works for running things in the container, thanks. It still leaves the problem of subsequent build steps. So I’ve ended up installing ROS with:

```auto
RUN apt-get install ros-XXX
ENTRYPOINT ["/ros/entrypoint.sh"] # your script above, runs /ros/setup.bash
RUN ["/bin/bash", "-c", ". /ros/setup.bash && setup-step-1"]
RUN ["/bin/bash", "-c", ". /ros/setup.bash && setup-step-2"]
RUN ["/bin/bash", "-c", ". /ros/setup.bash && setup-step-3"]
...

```

which is OK, but might make it annoying to support multiple such setup scripts. I was dreaming of something like

```auto
RUN bash -c ". /opt/ros/setup.bash && env | grep ROS" | ENV - # or some such syntax
RUN setup-step-1
RUN setup-step-2
RUN setup-step-3
...

```

but I can live without it.

---

<div class="post-metadata">

**Author:** ![dmaze](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@dmaze](https://forums.docker.com/u/dmaze)\
**Post date:** [June 10, 2016, 5:50pm UTC](https://forums.docker.com/t/bash-env-setup-scripts/15092/4 "2016-06-10T17:50:56Z")

</div>

Is the container a Debianish base? You could try

```auto
RUN ln -sf bash /bin/sh
RUN . /opt/ros/setup.bash \
 && setup-step-1 \
 && setup-step-2 \
 && c.

```
