ros2 / ros2cli

ROS 2 command line interface tools
Apache License 2.0
172 stars 161 forks source link

topic pub cannot handle multiple `!` lines up in a row #794

Closed fujitatomoya closed 1 year ago

fujitatomoya commented 1 year ago

Bug report

Required Info:

Steps to reproduce issue

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic echo /chatter
data: Hello ROS
---
data: Hello ROS!
---

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub --once /chatter std_msgs/msg/String "data: Hello ROS"
Waiting for at least 1 matching subscription(s)...
Waiting for at least 1 matching subscription(s)...
publisher: beginning loop
publishing #1: std_msgs.msg.String(data='Hello ROS')

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub --once /chatter std_msgs/msg/String "data: Hello ROS!"
publisher: beginning loop
publishing #1: std_msgs.msg.String(data='Hello ROS!')

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub --once /chatter std_msgs/msg/String "data: Hello ROS!!"
ros2 topic pub --once /chatter std_msgs/msg/String "data: Hello ROSros2 topic pub --once /chatter std_msgs/msg/String "data: Hello ROS!""
usage: ros2 [-h] [--use-python-default-buffering] Call `ros2 <command> -h` for more detailed usage. ...
ros2: error: unrecognized arguments: Hello ROS!

Expected behavior

successfully publishes ros2 topic pub --once /chatter std_msgs/msg/String "data: Hello ROS!!"

Actual behavior

fails to issue the command line.

root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub --once /chatter std_msgs/msg/String "data: Hello ROS!!"
ros2 topic pub --once /chatter std_msgs/msg/String "data: Hello ROSros2 topic pub --once /chatter std_msgs/msg/String "data: Hello ROS!""
usage: ros2 [-h] [--use-python-default-buffering] Call `ros2 <command> -h` for more detailed usage. ...
ros2: error: unrecognized arguments: Hello ROS!
fujitatomoya commented 1 year ago

@iuhilnehc-ynos any idea?

iuhilnehc-ynos commented 1 year ago

@fujitatomoya

It's not a bug. It's just a feature of bash.

!! in the bash can call the last command, and please see the double quotes.

Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ‘\’, and, when history expansion is enabled, ‘!’.

We can use \ or single quotes to avoid this issue.

$ ros2 topic pub --once /chatter std_msgs/msg/String "data: Hello ROS\!\!"
$ ros2 topic pub --once /chatter std_msgs/msg/String 'data: Hello ROS!!'
fujitatomoya commented 1 year ago

@iuhilnehc-ynos thanks for the comment. I actually did not realize that, thanks for the information.