Next: Repository Conventions, Previous: General Conventions, Up: Conventions
Shell is central to Carbs Linux projects. Most of the tools and packages are written in POSIX sh.
Use 4 spaces for indentation, don’t use tabs.
Make sure you don’t use bash-specific code.
Make sure you lint your code with shellcheck
and if you are new to
POSIX sh, use checkbashisms
.
Don’t spawn new processes if you don’t absolutely need to, especially during string manipulation.
Never use a program for text manupilation that isn’t defined in the POSIX
standard. This includes gawk
and perl
.
Instead of $(basename $file)
, use ${file##*}
.
Instead of $(dirname $file)
, use ${file%/*}
.
# This is the same thing as basename /path/to/test.asc .asc
$ file=/path/to/test.asc file=${file##*/} file=${file%.asc}
$ echo $file
test
Instead of backticks, use $(..).