Robotics StackExchange | Archived questions

Pass an argument inside a shell script file

HI,

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

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

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

Thanks, Aviad

Asked by Aviad on 2020-01-13 04:08:51 UTC

Comments

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

Asked by Abhishekpg on 2020-01-13 10:02:31 UTC

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.

Asked by Aviad on 2020-01-14 02:08:03 UTC

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.

Asked by gvdhoorn on 2020-01-15 04:41:45 UTC

Answers

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

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

#!/bin/bash

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

# Needed because first 2 Images have no corresponding features
if [ ! -z "$1" ]; then
    position="$1"
else
    position="front"
fi
if [ ! -z "$2" ]; then
    prefix="$2"
else
    prefix=""
fi
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"

Asked by GeorgNo on 2020-01-15 02:47:03 UTC

Comments