# ros2 launch: Substitution error: command 'my_script.sh' not found in PATH or launch directory

- **ID:** `ros2/ros2-launch-substitution-error-command-not-found`
- **Domain:** ros2
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

The launch file uses a command substitution (e.g., FindExecutable or ExecuteProcess) to locate an executable, but the executable is not in the system PATH or the launch file's package share directory.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Humble | active | — | — |
| Iron | active | — | — |
| Rolling | active | — | — |

## Workarounds

1. **Ensure the executable is in the PATH. For a shell script in your package, add it to the package's CMakeLists.txt: install(PROGRAMS scripts/my_script.sh DESTINATION lib/${PROJECT_NAME}). Then source the workspace and run: ros2 launch my_package my_launch.py** (90% success)
   ```
   Ensure the executable is in the PATH. For a shell script in your package, add it to the package's CMakeLists.txt: install(PROGRAMS scripts/my_script.sh DESTINATION lib/${PROJECT_NAME}). Then source the workspace and run: ros2 launch my_package my_launch.py
   ```
2. **Use FindExecutable substitution with the correct package and executable name. In launch file: from launch.substitutions import FindExecutable; executable = FindExecutable(name='my_script.sh'). Ensure the script is installed in the package's lib directory.** (85% success)
   ```
   Use FindExecutable substitution with the correct package and executable name. In launch file: from launch.substitutions import FindExecutable; executable = FindExecutable(name='my_script.sh'). Ensure the script is installed in the package's lib directory.
   ```
3. **If the script is external, add its directory to PATH before launching: export PATH=$PATH:/path/to/script/dir && ros2 launch my_package my_launch.py** (75% success)
   ```
   If the script is external, add its directory to PATH before launching: export PATH=$PATH:/path/to/script/dir && ros2 launch my_package my_launch.py
   ```

## Dead Ends

- **** — Even if the script is in the launch directory, the substitution uses the package's share directory, not the source directory. You must install the script via CMake or set the PATH. (90% fail)
- **** — Absolute paths work only on the specific machine they were written for. They break when the workspace is moved or shared with other developers. (80% fail)
