Always use environment variables or configuration mechanisms instead of hardcoding paths to compilers, tools, or directories. Hardcoded paths create dependencies on specific environments and break compatibility across different platforms and CI systems.
Always use environment variables or configuration mechanisms instead of hardcoding paths to compilers, tools, or directories. Hardcoded paths create dependencies on specific environments and break compatibility across different platforms and CI systems.
Bad:
#!/bin/bash
CXX=/usr/bin/g++
Good:
#!/bin/bash
# Use environment variable if set, otherwise use default
CXX=${CXX:-g++}
For specialized environment paths, use specific environment variables that users can customize:
Bad:
export CMAKE_COMMAND="$CMAKE_COMMAND -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake"
Good:
# Allow users to specify RPI_HOME environment variable
export RPI_HOME=${RPI_HOME:-$HOME/raspberrypi}
export CMAKE_COMMAND="$CMAKE_COMMAND -D CMAKE_TOOLCHAIN_FILE=$RPI_HOME/pi.cmake"
This approach ensures scripts remain portable across different development environments, CI systems, and operating systems.
Enter the URL of a public GitHub repository