1

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

user244985
  • 121
  • 3
  • 10
  • 1
    try using the `'` and not the `"` as delimiter – user2485710 Mar 17 '14 at 18:24
  • possible duplicate of [Difference between single and double quotes in bash](http://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash) – Barmar Mar 17 '14 at 18:26
  • @Barmar I apologize if this is a duplicate. – user244985 Mar 17 '14 at 18:31
  • No apology necessary. If you'd known that the problem was with the type of quotes, you wouldn't have asked the question, so you couldn't have known that it was a dupe of that. – Barmar Mar 17 '14 at 18:34

2 Answers2

1

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.

Adrian Ratnapala
  • 5,485
  • 2
  • 29
  • 39
1

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

grahamlyons
  • 687
  • 5
  • 15