In a bash script I have it is supposed to write certain lines to a file. This is what it supposed to write:

echo "export ROS_PACKAGE_PATH=/home/forklift/forklift-workspace:$ROS_PACKAGE_PATH" >> ~/.bashrc

and this is what it writes in the file:

export ROS_PACKAGE_PATH=/home/forklift/forklift-workspace:

how do I fix this? I'm using Ubuntu

Any help is appreciated!!

有帮助吗?

解决方案

This is expected if the variable $ROS_PACKAGE_PATH is not defined (or equal to "") when echo is called. If I understand what you are trying to do, then you can just replace the double-quotes with single quote to prevent this behaviour. Thus

echo 'export ROS_PACKAGE_PATH=/home/forklift/forklift-workspace:$ROS_PACKAGE_PATH' >> ~/.bashrc

Should add the line

export ROS_PACKAGE_PATH=/home/forklift/forklift-workspace:$ROS_PACKAGE_PATH

to your .bashrc.

其他提示

The $ROS_PACKAGE_PATH in the string is being interpolated as a variable, but it doesn't exist in the environment so it just comes out blank.

It needs to be escaped with a \, like this:

echo "export ROS_PACKAGE_PATH=/home/forklift/forklift-workspace:\$ROS_PACKAGE_PATH" >> ~/.bashrc

For more in-depth information on parameter expansion, this is pretty comprehensive: http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top