|
LackFunctions
Documentation for the lack_functions.sh script
Back to the MainPage... lack_functions.shThe lack_functions.sh script defines a set of shell functions and variables; most of the variables contain different parts of the ANSI escape sequences for colorizing text on a Linux console. Instead of having to remember the characters that make up a specific ANSI sequence, you can just throw the shell variable in there and things will Just Work. In order to use these in scripts, just source the lack_functions.sh script, then call any of the below shell variables as $VARIABLE in your scripts. Commonly used strings
Example usage, sets text foreground color to red then resets at the end of the line: echo ${START}${FG_RED}${END}This is an example of "${FAILED}"${START}${NONE}${END}Colorization shortcuts
ANSI text sequencesShell variables with pre-configured ANSI escape sequences for colorization. Text attributes
Background text colors
Foreground text colors
Note that not all color combinations are available on all consoles/terminal emulators; your best bet is to try something out first before you put it into production. colorize ()Arguments:
Colorizes a block of text, but does not output a newline at the end of the line. Example usage: colorize "$F_RED;$B_BLU" "This is red text on a blue background" colorize_nl ()Arguments:
Colorizes a block of text, adds a newline at the end of the line. Example usage: colorize_nl "$F_RED;$B_BLU" "This is red text on a blue background" pause_prompt ()Arguments:
Checks for a $PAUSE_PROMPT variable defined in the shell environment, and if it exists, prompts the user to hit the <Enter> key prior to continuing script execution. This is used for debugging/troubleshooting, to prevent valuable text from scrolling off of the console buffer. Example usage: export PAUSE_PROMPT=1 pause_prompt cmd_status ()Arguments:
Checks the output of the last executed command for errors; prompts for a shell if the $DEBUG environment variable is set. Example usage: /bin/true cmd_status $? "/bin/true" /bin/false cmd_status $? "/bin/false" # running /bin/false should output an error message want_shell ()Arguments:
Reads the $DEBUG environment variable to determine whether or not to prompt the user for a shell; if $DEBUG is not set, the user is not prompted. Your script should set $DEBUG to something prior to executing the want_shell function. Example usage: DEBUG=1 want_shell # user is prompted for a shell file_parse ()Arguments:
Reads the specified file, grepping for the specified string; returns a substring of the matched string containing all text after the first equals sign =. Sets the $PARSED environment variable with the string that was parsed out of the file. Example usage: echo "string=value" > /tmp/test.txt # later on, somewhere in a shell script... file_parse /tmp/test.txt "string" # $PARSED would then contain 'value' get_pid ()Arguments:
Returns the child PID as $CHILD_PID. Example usage: /bin/someprogram & get_pid "someprogram" echo $CHILD_PID # outputs the PID of 'someprogram' write_child_pid ()Arguments:
Writes the child PID into the file /var/run/${CHILD_BINARY}.pid. Meanted to be used with get_pid () above to write out PID files for processes that don't create their own. Example usage: /bin/someprogram & get_pid "someprogram" write_child_pid "someprogram" cat /var/run/someprogram.pid # outputs the PID of 'someprogram' get_hostname ()Arguments:
Sets $HOSTNAME with the hostname of the machine, as obtained from the file /etc/hostname. Outputs an error if /etc/hostname does not exist. get_kernel_version ()Arguments:
Sets environment variables for the kernel major, minor and patch version numbers as:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||