From 183e7f40a260ef6e09745183ce768986bab29daf Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 7 May 2021 15:51:28 +0200 Subject: [PATCH] libstd.bash: function to check Bash variable type added --- Pmodules/libstd.bash | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Pmodules/libstd.bash b/Pmodules/libstd.bash index eb8525d..e5a2f46 100644 --- a/Pmodules/libstd.bash +++ b/Pmodules/libstd.bash @@ -244,6 +244,33 @@ std::get_os_release() { ${func_map[${OS}]} } +std::get_type() { + local -a signature=$(typeset -p "$1") + case ${signature[1]} in + -Ai* ) + echo 'int dict' + ;; + -A* ) + echo 'dict' + ;; + -ai* ) + echo 'int array' + ;; + -a* ) + echo 'array' + ;; + -i* ) + echo 'integer' + ;; + -- ) + echo 'string' + ;; + * ) + echo 'none' + return 1 + esac +} + # Local Variables: # mode: sh # sh-basic-offset: 8