]> lifelog.hopto.org Git - wb-shell-scripts.git/commitdiff
Added -g rep options.
authorWill Budic <redacted>
Thu, 2 Oct 2025 10:33:18 +0000 (20:33 +1000)
committerWill Budic <redacted>
Thu, 2 Oct 2025 10:33:18 +0000 (20:33 +1000)
uvar.sh

diff --git a/uvar.sh b/uvar.sh
index f919f5f7009341f9bb0e6762ad0744aae2a95227..4d9f4b19ce7a8d3f5338e10f1b724df77a02e641 100755 (executable)
--- 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;