ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Provide empty string as roslaunch argument substitution

asked 2018-07-03 10:16:28 -0500

artifactz gravatar image

I have a default.launch file with some arguments and default values (strings).

I would like to substitute a default value with an empty string while launching, e.g.

roslaunch pkg default.launch arg1:=""

But the substitution is ignored. Also ignored are:

roslaunch pkg default.launch arg1:=''
roslaunch pkg default.launch arg1:=" "


Working substitutions are:

roslaunch pkg default.launch arg1:="!"
roslaunch pkg default.launch arg1:='test'


How can I provide an empty string as an argument substitution?

edit retag flag offensive close merge delete


I've messed with this for a while and can't get it. You can set an empty string as the default value and that works. What are you trying to achieve with this? Would an empty string default work for you?

adamconkey gravatar image adamconkey  ( 2018-07-03 14:33:46 -0500 )edit

Thank you for your feedback. E.g. I have an argument which defaults to /sonar, because that's the default sonar topic. An empty string disables sonar processing. I guess the easiest workaround would be creating a new launch file.

artifactz gravatar image artifactz  ( 2018-07-05 07:59:18 -0500 )edit

I opened an issue at GitHub.

artifactz gravatar image artifactz  ( 2018-07-05 09:42:09 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2019-03-01 09:23:33 -0500

artifactz gravatar image

A friendly GitHub user reminded me, that in bash you use quotation marks to group space-separated strings as a single argument, so everything ROS receives is roslaunch pkg default.launch arg1:=.

To keep the quotes, you can use single quotes around the double qoutes:

roslaunch pkg default.launch arg1:='""'
edit flag offensive delete link more


It doesn't work

xinwf gravatar image xinwf  ( 2019-08-02 20:36:28 -0500 )edit

answered 2018-07-04 03:26:53 -0500

Reamees gravatar image

updated 2018-07-04 06:28:06 -0500

As aconkey said giving an empty string from the command line does not seem to work. I'm not sure this is the cleanest solution, but you could hack together the desired behavior to some extent with eval and an intermediate argument. Something like this:

    <arg name="arg1"           default="some_value"/>
    <arg name="arg1_helper"    default="$(eval '' if (arg1 == '!') else arg1)"/>

    <include file="$(find pkg)/launch/$(arg arg1_helper)_node.launch">

roslaunch pkg default.launch arg1:=!

arg1_helper will evaluate to "" and will try to launch pkg/launch/_node.launch

roslaunch pkg default.launch arg1:=some_other_value

arg1_helper will evaluate to "some_other_value" and will try to launch pkg/launch/some_other_value_node.launch

roslaunch pkg default.launch

arg1_helper will evaluate to the default value "some_value" and will try to launch pkg/launch/some_value_node.launch

The downsides to this approach would be that you have to have an extra argument in your launch files and instead of arg1:="" you would have to use arg1:=! (or what ever else you set eval to) to set the argument as an empty string.

edit flag offensive delete link more


Thank you for your idea and your feedback. I guess I'm just going to create a simple launch file including default.launch and overriding the argument there.

artifactz gravatar image artifactz  ( 2018-07-05 08:02:04 -0500 )edit

Question Tools



Asked: 2018-07-03 10:16:28 -0500

Seen: 1,788 times

Last updated: Mar 01 '19