From 77822e5d20f431cf640ff8f621370042d68e75a1 Mon Sep 17 00:00:00 2001 From: Will Budic Date: Thu, 2 Oct 2025 20:33:18 +1000 Subject: [PATCH] Added -g rep options. --- uvar.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/uvar.sh b/uvar.sh index f919f5f..4d9f4b1 100755 --- a/uvar.sh +++ b/uvar.sh @@ -15,6 +15,7 @@ Making them global named values to sessions, between logins and subsequent bash -e - Option turns environmental variable into a user variable or error if not defined. -r - Read named variable. -l - List all the available user variables. +-g - List grep case insensitive by name available user variables. -o - Output only the value of named variable, pipes out piped in. -d - Delete the named uvar. -s - Alternative store location (not recommended option to use). @@ -78,16 +79,20 @@ fi [[ "$print" -eq "1" ]] && echo "$2" exit; } -function list(){ +function list_grep(){ +#echo -e "$1=$2 - $argc" for file in $STORE/.uvar_* do -#echo $file n=$(echo $file | sed "s/$EXP//") if [[ -f $file ]]; then v=$(awk '{if (NR<6) print}END{if(NR > 5) \ print "\t---> THE DISPLAY HAS BEEN CUT AT LINE 5 FOR [" ARGV[1] "] <---\n\n"}' \ $file) - echo -e "$n=$v" + if [[ -z "$1" ]]; then + echo -e "$n=$v" + else + echo -e "$n=$v" | grep -i "$1" + fi fi done } @@ -109,7 +114,7 @@ argc=$# argv=("$@") print=0 -while getopts ":e:d:r:n:v:s:f:p:lo" opt +while getopts ":e:d:g:r:n:v:s:f:p:lo" opt do case "${opt}" in s) if [[ -d "${OPTARG}" ]]; then @@ -127,7 +132,9 @@ do n) name=${OPTARG};; v) value=${OPTARG};; r) readUVAR ${OPTARG};; - l) list;; + g) list_grep ${OPTARG} + exit;; + l) list_grep;; f) [[ -f $STORE/.uvar_$name ]] && $(rm -f $STORE/.uvar_$name); while read line; do echo -e "$line" >> $STORE/.uvar_$name @@ -163,4 +170,4 @@ if [[ $# > 1 ]]; then name=$1; shift; value="$@" writeUVAR $name "$value" fi -exit; \ No newline at end of file +exit; -- 2.34.1