π Get Values Tools
Utilities for extracting information.
import_configβ
Converts prop lines (a = b) from a file into variables ($a).
Argument | Description |
---|---|
FILE | Prop file |
# example.prop: name=Some name, current_version=v1.1.0, i_d_k=S o m e t h i n g
import_config "$TMP/example.prop"
ui_print "$name" # Prints "Some name"
ui_print "$current_version" # Prints "v1.1.0"
ui_print "$i_d_k" # Prints "S o m e t h i n g"
note
Props with special characters wonβt become variables.
get_file_propβ
Extracts a property from one or more prop files.
Argument | Description |
---|---|
FILE | Prop file(s) |
PROP | Property to extract |
get_file_prop /system/build.prop "ro.build.display.id"
# Multiple files
get_file_prop /system/build.prop /vendor/build.prop /system_ext/build.prop "ro.build.display.id"
# Store result
myid=$(get_file_prop /system/build.prop "ro.build.display.id")
note
The search will stop at the first match, always returning a single value.
map_file_propsβ
Maps multiple properties from one or more files into an array.
Flag | Description |
---|---|
-var (-v) | Name of the array to store results. |
-files (-f) | Files to search. |
-props (-p) | Properties to find. |
Example:
map_file_props -v my_array -f "/sdcard/file1.prop" "/sdcard/file2.prop" -p "ro.build.version" "ro.product.model"
ui_print "${my_array[0]}" # ro.build.version value
ui_print "${my_array[1]}" # ro.product.model value
note
- The search will stop when at least one match for each property has been found. That is, only the value of the first match for each property is considered.
- An ordered array is always guaranteed, even if one of the properties was not found. Its corresponding space will be filled with an empty value.
getdefaultβ
Extracts setdefault
values from a file (no multi-line support).
Argument | Description |
---|---|
FILE | File with setdefault lines |
KEY | Key to extract |
# something.txt: setdefault ole "a b c", setdefault okay "d e f", setdefault test "s o m e t h i n g"
getdefault "$TMP/something.txt" okay # Returns "d e f"
getdefault "$TMP/something.txt" test # Returns "s o m e t h i n g"
# Store result
my_var=$(getdefault "$TMP/something.txt" okay)
get_arrayβ
Gets a full value from an array matching a pattern.
Argument | Description |
---|---|
PATTERN | Pattern to match |
ARRAY | Array to search |
test=("First array" "Other array" "A B")
get_array "Other" "${test[@]}" # Returns "Other array"
# Store result
content=$(get_array "Other" "${test[@]}")
get_size_ext4β
Gets the size in bytes of an ext4 partition or RAW .img.
Argument | Description |
---|---|
PATH | Partition or .img file |
get_size_ext4 "$(find_block system)"
# From file
get_size_ext4 "/sdcard/vendor.img"
# Store result
size=$(get_size_ext4 "$(find_block system)")
fullpathβ
Gets the full path of a file, folder, or symlink (returns literal symlink paths).
Argument | Description |
---|---|
PATH | File, folder, or symlink |
fullpath "folder/file"
# Store result
complete_path=$(fullpath "folder/file")