Ask Your Question

Pass an argument inside a shell script file

asked 2020-01-13 03:08:51 -0500

Aviad gravatar image


I want to execute .sh file and pass an arguments inside this file. For example: I have this script:

source /opt/ros/kinetic/setup.bash
source ~/catkin_ws/devel/setup.bash
roslaunch ur_modern_driver ur5_bringup.launch robot_ip:=

I can execute from terminal by runnign ./ but It is not taking care the argument robot_ip How can I pass this arguments inside the shell script?

Thanks, Aviad

edit retag flag offensive close merge delete


Please share your output. What do you mean by it is not taking care of robot_ip

Abhishekpg gravatar image Abhishekpg  ( 2020-01-13 09:02:31 -0500 )edit

I want to launch some launch file with an argumnent rviz for example. If I run in terminal roslaunch pkg file.launch rviz:=true I want rviz to open. Inside the terminal it is working of course but If it is wrote inside a .sh file the arg rviz is not pass like in the terminal.

Aviad gravatar image Aviad  ( 2020-01-14 01:08:03 -0500 )edit

Please also note:

roslaunch ur_modern_driver [..]

this package has been deprecated, as mentioned in the readme. See also Deprecation of ur_modern_driver on ROS Discourse.

If you have a CB3 controller with your UR robot, you should not be using ur_modern_driver any more.

gvdhoorn gravatar image gvdhoorn  ( 2020-01-15 03:41:45 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-01-15 01:47:03 -0500

GeorgNo gravatar image

I think you need to put the ip like this robot_ip:="".

Here is a bash file that works for me (Ubuntu 18.04, ROS Melodic)


echo "Num args: $#"
echo "Args: $@"

# Needed because first 2 Images have no corresponding features
if [ ! -z "$1" ]; then
if [ ! -z "$2" ]; then
echo "Position: >$position<"
echo "Prefix= >$prefix<"

rostopic echo /prius/stereo_camera_front/left/image_raw -n 2 >/dev/null 2>&1
set -xv
roslaunch prius stereo_mapping.launch position:=$position prefix:="$prefix"
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-01-13 03:08:51 -0500

Seen: 101 times

Last updated: Jan 15 '20