You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constchar *command_filepath = commandname; // if we can't find it trust in PATH
Unfortunately, trusting in $PATH is a hazardous course of action! This function uses sh to invoke the program. On my system (Ubuntu 18.04), sh is symlinked to dash, which does NOT search $PATH when given a command that doesn't include a slash.
The man page makes it sound like it does, but it doesn't.
Path Search
When locating a command, the shell first looks to see if it has a shell function by that name. Then it looks for a builtin command by that name. If a builtin command is not found, one of two things happen:
1. Command names containing a slash are simply executed without performing any searches.
2. The shell searches each entry in PATH in turn for the command. The value of the PATH variable should be a series of entries separated by colons. Each entry consists of a directory name. The current directory may be indicated implicitly by an empty directory name, or explicitly by a single period.
$ mkdir test
$ echo -e '#!/bin/sh\necho $0 "$@"\n' >test/test.sh
$ PATH=$PWD/test:$PATH bash test.sh 1 2 3
test.sh 1 2 3
$ PATH=$PWD/test:$PATH dash test.sh 1 2 3
dash: 0: cannot open test.sh: No such file
Here are a couple of workarounds:
Use bash instead of sh
Use sh -c, but note that in that case the full command needs to be in quotes, i.e. sh -c "dumpstack.sh PID" or sh -c "dumpstack.sh $0" PID
If the command isn't found in one of the canned search directories, find it from $PATH using which, then pass that to sh
@durka OK, you've obviously got a slightly weird setup where it can't find the thing in the path it is expecting, but that you are adding that scripts directory to the path.
I'm uncomfortable changing that code for everyone, but please see the PR I just created (#27742) to give people some sort of an option, at least.
Bug report
Issue details
There is a comment here:
ardupilot/libraries/AP_HAL_SITL/system.cpp
Line 58 in a480c0a
Unfortunately, trusting in
$PATH
is a hazardous course of action! This function usessh
to invoke the program. On my system (Ubuntu 18.04),sh
is symlinked todash
, which does NOT search$PATH
when given a command that doesn't include a slash.The man page makes it sound like it does, but it doesn't.
Here are a couple of workarounds:
bash
instead ofsh
sh -c
, but note that in that case the full command needs to be in quotes, i.e.sh -c "dumpstack.sh PID"
orsh -c "dumpstack.sh $0" PID
$PATH
usingwhich
, then pass that tosh
Version
4.2.3
Platform
[ ] All
[ ] AntennaTracker
[ ] Copter
[ ] Plane
[ ] Rover
[ ] Submarine
[x] SITL
Airframe type
N/A
Hardware type
N/A
Logs
N/A
The text was updated successfully, but these errors were encountered: