2.0 KiB
ao-bash Opinionated Code Style Guide
This script is a style guide for the ao-bash / ao-mud project and is not meant to be run. Please examine the file in a text editor.
This file represents the current moment of consensus for best practices or de facto policy for the ao-bash / ao-mud project. Please don't take it as the final word; if you would like to critique or improve this document and the best practices it contains, please do so.
File Extensions
Name scripts in the ao-bash suite without the .sh
file extension. (Reason: When folders of ao-bash spells are added to the $PATH directory, the scripts can simply be called by name, without having to type .sh
every time.)
How to print something to the terminal
say
is an ao-bash command that uses printf to echo a line to a screen (it adds the \n to the end and thus functions like echo).
printf
is preferred to echo
because it is more cross-platform, however realistically echo will also be used and should also work in virtually all cases. Note that printf
needs a \n explicitly at the end of the string, and also includes more advanced options for formatting variables that it displays.
How to ask the user a question
ask
is an ao-bash suite command that asks the user an open-ended question, and outputs their response (which can be saved in a variable). Use it like this:
answer=ask "Please enter your name:"
ask_yn
is a similar command that takes a question, plus an optional second argument Y or N that defines the default response if the user presses Enter (if the second argument is not supplied, it defaults to N):
ask_yn "Would you like a treatment?" Y
Style References
These projects and links provide a reference for the overall aesthetic approach of this project: