[Documentation] [TitleIndex] [WordIndex

  Show EOL distros: 

Package Summary

Tools for writing ros-node-like bash scripts

  • Maintainer status: developed
  • Maintainer: Martin Pecka <peckama2 AT fel.cvut DOT cz>
  • Author: Martin Pecka <peckama2 AT fel.cvut DOT cz>
  • License: BSD
  • Source: git https://github.com/peci1/rosbash_params.git (branch: master)

Package Summary

Tools for writing ros-node-like bash scripts

  • Maintainer status: developed
  • Maintainer: Martin Pecka <peckama2 AT fel.cvut DOT cz>
  • Author: Martin Pecka <peckama2 AT fel.cvut DOT cz>
  • License: BSD
  • Source: git https://github.com/peci1/rosbash_params.git (branch: master)

Package Summary

Tools for writing ros-node-like bash scripts

  • Maintainer status: developed
  • Maintainer: Martin Pecka <peckama2 AT fel.cvut DOT cz>
  • Author: Martin Pecka <peckama2 AT fel.cvut DOT cz>
  • License: BSD
  • Source: git https://github.com/peci1/rosbash_params.git (branch: master)

Package Summary

Tools for writing ros-node-like bash scripts

  • Maintainer status: developed
  • Maintainer: Martin Pecka <peckama2 AT fel.cvut DOT cz>
  • Author: Martin Pecka <peckama2 AT fel.cvut DOT cz>
  • License: BSD
  • Source: git https://github.com/peci1/rosbash_params.git (branch: master)

Package Summary

Tools for writing ros-node-like bash scripts

  • Maintainer status: maintained
  • Maintainer: Martin Pecka <peckama2 AT fel.cvut DOT cz>
  • Author: Martin Pecka <peckama2 AT fel.cvut DOT cz>
  • License: BSD
  • Source: git https://github.com/peci1/rosbash_params.git (branch: master)

This Bash env-hook adds a "node-like" interface to your code written in Bash. The main thing it adds is ROS-like command-line parameter parsing (_param:=value), so that you can easily call the Bash script from a launch file like

<node name="test" pkg="pkg" type="my_bash_script.sh">
    <param name="par" value="test" />
</node>

Advantages

Usage

Example script test_rosbash

rosbash_init_node "node_name" "$@"  # parse the command line arguments

rosbash_param mandatory_param "param_name"  # if default value is not specified, the param is mandatory
rosbash_param optional_param "param2_name" "default_value" # optional param
rosbash_param bool_param1 "bool_name1" # bool param without default
rosbash_param bool_param2 "bool_name2" "True" # bool param with default
rosbash_param bool_param3 "bool_name3" "False" # bool param with default

echo "mandatory_param = ${mandatory_param}"  # access the parsed parameter value
echo "optional_param = ${optional_param}"  # access the parsed parameter value
echo "bool_param1 = ${bool_param1}"  # access the parsed parameter value
echo "bool_param2 = ${bool_param2}"  # access the parsed parameter value
echo "bool_param3 = ${bool_param3}"  # access the parsed parameter value

echo "rosbash_unused_argv = ${rosbash_unused_argv[@]}"  # all CLI args not parsed as a parameter 

Example call:

$ ./test_rosbash _param_name:=1 _unparsed_param:=2 positional1 positional2 _bool_name1:=False
mandatory_param = 1
optional_param = default_value
bool_param1 = False
bool_param2 = True
bool_param3 = False
rosbash_unused_argv = _unparsed_param:=2 positional1 positional2

Example call with missing mandatory parameter:

$ ./test_rosbash positional1 positional2
Required parameter 'param_name' was not set.

Example call showing bool behavior

$ ./test_rosbash  _param_name:=test _bool_name1:=1 _bool_name2:=0 _bool_name3:=on
mandatory_param = test
optional_param = default_value
bool_param1 = 1  # without default value, we cannot safely convert all `1`s to `True`
bool_param2 = False  # with default value either `True` or `False`, we can convert `1` to `True` and `0` to `False`
bool_param3 = True  # `on` without quotes is always converted to `True`
rosbash_unused_argv = 

Example launch file

<launch>
    <node name="test" pkg="test_pkg" type="test_rosbash">
        <param name="param_name" value="test" />
        <param name="param2_name" value="optional" />
        <param name="bool_name1" value="off" />
    </node>
</launch>

API

rosbash_init_node

Arguments

Global variables set by this function

rosbash_param

Be sure to call rosbash_init_node before calling this function!

Arguments

Environment variables

ROS_BASH_PARAM_EXIT=0 rosbash_param var "mandatory" || echo "Please, fill the mandatory param"

Other shells

As I don't use any other shells, this package only supports Bash. But theoretically it can work in many other shells, so if you want them supported, feel free to send a pull request (not issues, I won't write support for other shells myself).


2024-12-07 18:16