Ask Your Question
0

Pass an argument inside a shell script file

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

Aviad gravatar image

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 ./script_name.sh 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

Comments

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

Abhishekpg gravatar imageAbhishekpg ( 2020-01-13 09:02:31 -0600 )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 imageAviad ( 2020-01-14 01:08:03 -0600 )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 imagegvdhoorn ( 2020-01-15 03:41:45 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

GeorgNo gravatar image

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"
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

Stats

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

Seen: 20 times

Last updated: Jan 15