Coder Social home page Coder Social logo

Comments (5)

pawanw17 avatar pawanw17 commented on July 29, 2024 1

@pariaspe I tested adding stuff in ~/.bash_profile and ~/.profile and opened a new terminal using docker exec

and ran ros2 list and got errors indicating the files weren't sourced, this is probably due because our shells aren't executed with --login

TL;DR ~/.bash_profile won't work for us

from roboticsacademy.

pariaspe avatar pariaspe commented on July 29, 2024

ROS packages are sourced from .bashrc which is meant to be used in interactive sessions only:

$ head ./bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

Script is returning before sourcing when the entrypoint is run directly. Easiest way to solve is to overwrite .bashrc file. We can also create another script for sourcing or source it from entrypoint.sh directly (or .env). What do you think @pawanw17 ?

from roboticsacademy.

pawanw17 avatar pawanw17 commented on July 29, 2024

Having the sources in .bashrc certainly helps during debugging and development, as we don't have to source them every time we open a new terminal attached to docker. I was wondering if there is a file that is sourced in both interactive and non-interactive shells.

I am not sure maybe overwriting .bashrc could lead to other errors, not too confident of this solution.

I'd suggest that we have it in .bashrc as well as .env/entrypoint.sh

from roboticsacademy.

pariaspe avatar pariaspe commented on July 29, 2024

Ok, then I'll create a .bash_profile with all needed sources and this file will be source both in .bashrc and entrypoint.sh.

Also, I've been reading bash manual entry and I might come with another solution:

$ man bash

       ...

       The  following paragraphs describe how bash executes its startup files.
       If any of the files exist but cannot be read, bash  reports  an  error.
       Tildes  are expanded in filenames as described below under Tilde Expan‐
       sion in the EXPANSION section.

       When bash is invoked as an interactive login shell, or as a  non-inter‐
       active  shell with the --login option, it first reads and executes com‐
       mands from the file /etc/profile, if that file exists.   After  reading
       that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
       in that order, and reads and executes commands from the first one  that
       exists  and  is  readable.  The --noprofile option may be used when the
       shell is started to inhibit this behavior.

       When an interactive login shell exits, or a non-interactive login shell
       executes  the  exit  builtin  command, bash reads and executes commands
       from the file ~/.bash_logout, if it exists.

       When an interactive shell that is not a login shell  is  started,  bash
       reads  and  executes  commands  from /etc/bash.bashrc and ~/.bashrc, if
       these files exist.  This may be inhibited by using the  --norc  option.
       The  --rcfile  file option will force bash to read and execute commands
       from file instead of /etc/bash.bashrc and ~/.bashrc.

       When bash is started non-interactively, to run a shell script, for  ex‐
       ample,  it  looks for the variable BASH_ENV in the environment, expands
       its value if it appears there, and uses the expanded value as the  name
       of  a  file to read and execute.  Bash behaves as if the following com‐
       mand were executed:
              if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
       but the value of the PATH variable is not used to search for the  file‐
       name.

from roboticsacademy.

pariaspe avatar pariaspe commented on July 29, 2024

Many thanks for the testing @pawanw17 👍

I figured out a smoothly way to do it. It works for non-interactive and interactive shells. Setting BASH_ENV to the file where we are setting up the environment: .env

from roboticsacademy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.