Next: , Previous: , Up: Conventions   [Contents]


4.1.2 Shell Conventions – 10

Shell is central to Carbs Linux projects. Most of the tools and packages are written in POSIX sh.

[1010]

Use 4 spaces for indentation, don’t use tabs.

[1020]

Make sure you don’t use bash-specific code.

[1030]

Make sure you lint your code with shellcheck and if you are new to POSIX sh, use checkbashisms.

[1040]

Don’t spawn new processes if you don’t absolutely need to, especially during string manipulation.

[1041]

Never use a program for text manupilation that isn’t defined in the POSIX standard. This includes gawk and perl.

[1042]

Instead of $(basename $file), use ${file##*}.

[1043]

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
[1050]

Instead of backticks, use $(..).