This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | fuss:bash [2017/02/22 18:30] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Glob ====== | ||
+ | |||
+ | '' | ||
+ | |||
+ | ^ Glob ^ Explanation ^ | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | |||
+ | ===== Range ===== | ||
+ | |||
+ | ^ Glob ^ Explanation ^ | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | ''< | ||
+ | | ''< | ||
+ | | ''< | ||
+ | | ''< | ||
+ | |||
+ | |||
+ | ====== Increment in Bash Arrays ====== | ||
+ | |||
+ | <code bash> | ||
+ | array[$[${# | ||
+ | </ | ||
+ | |||
+ | is homologous to: | ||
+ | |||
+ | <code bash> | ||
+ | array[elements_in(array)+1] = 3 | ||
+ | </ | ||
+ | |||
+ | ====== String Substitute ====== | ||
+ | |||
+ | '' | ||
+ | <code bash> | ||
+ | T=" | ||
+ | echo ${T/ | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | <code bash> | ||
+ | test.png | ||
+ | </ | ||
+ | |||
+ | ====== Check if String Contains a Substring ====== | ||
+ | |||
+ | <code bash> | ||
+ | CHECK_STRING=" | ||
+ | if [[ " | ||
+ | echo " | ||
+ | fi | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== Split a String to an Array and other Array Manipulations ====== | ||
+ | |||
+ | The following code: | ||
+ | <code bash> | ||
+ | IFS=' ' read -ra VAR_ARRAY <<< | ||
+ | </ | ||
+ | |||
+ | where: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | will split the input to an array. | ||
+ | |||
+ | In order to iterate over the elements of the array, one would write: | ||
+ | <code bash> | ||
+ | for e in " | ||
+ | echo $e | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | which will print out all the elements in the array. | ||
+ | |||
+ | To get both the index and the value while iterating over the array, one would write: | ||
+ | <code bash> | ||
+ | for i in " | ||
+ | echo "$i ${VAR_ARRAY[i]}" | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | where on every iteration '' | ||
+ | |||
+ | To get the number of elements in the array, one would write: | ||
+ | <code bash> | ||
+ | echo " | ||
+ | </ | ||
+ | |||
+ | ====== Get the CPU Core Temperature File ====== | ||
+ | |||
+ | If you use '' | ||
+ | <code bash> | ||
+ | ########################################################################### | ||
+ | ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ## | ||
+ | ########################################################################### | ||
+ | function getCoreTemperatureFile { | ||
+ | for i in / | ||
+ | IFS=' ' read -ra CORE <<< | ||
+ | if [ " | ||
+ | echo " | ||
+ | fi | ||
+ | done | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | an example call, would then be: | ||
+ | <code bash> | ||
+ | CPU0_TEMPERATURE_FILE=$(getCoreTemperatureFile 0) | ||
+ | echo $CPU0_TEMPERATURE_FILE | ||
+ | </ | ||
+ | |||
+ | in order to retrieve the temperature of the first core ('' | ||
+ | |||