rodrigoqueiroz / geoscenarioserver

8 stars 1 forks source link

Checking Availability of the rosversion Command #38

Closed mchlswyr closed 3 years ago

mchlswyr commented 3 years ago

There is a problem with the logic here. If which rosversion is false (i.e., the rosversion command isn't found), then it will go ahead and run ROS_VERSION=$(rosversion -ds), which doesn't make any sense since we've already determined that the rosversion command doesn't exist.

It should be something like:

if ! which rosversion > /dev/null || [[ $(rosversion -d) == "<unknown>" ]]; then
    echo "No ROS distribution was found. Ensure that /opt/ros/<ROS version>/setup.bash is sourced."
    exit 1
fi

This way, only if which rosversion is successful and rosversion -d is successful (e.g., returns melodic), then the if-block will be skipped. This is the only case where the || condition is false.

mantkiew commented 3 years ago

I think it's important to execute $(rosversion -sd), the -s option ensures there's no new line character at the end of the output.