]> lifelog.hopto.org Git - wb-shell-scripts.git/commitdiff
Added -p /dev/stdin pipe optron for value.
authorWill Budic <redacted>
Tue, 17 Dec 2024 11:03:53 +0000 (22:03 +1100)
committerWill Budic <redacted>
Tue, 17 Dec 2024 11:03:53 +0000 (22:03 +1100)
uvar.sh

diff --git a/uvar.sh b/uvar.sh
index e13d0c4c900ce01133c057543c76f140e8f39e1e..f919f5f7009341f9bb0e6762ad0744aae2a95227 100755 (executable)
--- a/uvar.sh
+++ b/uvar.sh
@@ -7,7 +7,7 @@ cat <<EOF
 * User Variable Utility *
 
 User variables once are persisted and always available for the current user.
-Making them gloabal named values to sessions, between logins and subsequent bash calls or shells.
+Making them global named values to sessions, between logins and subsequent bash calls or shells.
 
 --- Options ---
 -n - Name of variable
@@ -20,12 +20,14 @@ Making them gloabal named values to sessions, between logins and subsequent bash
 -s - Alternative store location (not recommended option to use).
      Default store location is ~/.config. 
      Setting it to $0 -s /var/tmp will store to temporary storage that is volatile memory.
--f - Copy file into an named uvar. i.e. uvar -n MY_FILE -f some_sile.ext.
+-f - Copy file into an named uvar. i.e. uvar -n MY_FILE -f some_file.ext.
+-p - Write STDIN as value to and uvar, value option is ignore.
 
 Usage: $0 {-o,-l} -n {name} -v {value} -r {name} {value}
 $0 {name}
 $0 {name} {value}
 $0 -l
+echo 'multiline\n value' | $0 -p SOME_NAME
 
 ---
 Uvar's are persisted as ~/.config/.uvar_* type of files.
@@ -58,6 +60,7 @@ exit;
 #        as it rises access errors in cron jobs.
 [[ -z $CRON_DISABLED_STDIN ]] &&  [[ ! -t 0 ]] && value=$(</dev/stdin) 
 
+
 function readUVAR(){
 var=$STORE/.uvar_$1;
 if [ -f $var ]; then
@@ -81,8 +84,8 @@ do
 #echo $file
 n=$(echo $file | sed "s/$EXP//")
 if [[ -f $file ]]; then
-     v=$(awk '{if (NR<6) print}END{if(NR > 5) \
-             print "---> THE VALUE DISPLAY OFF HAS BEEN CUT AT LINE 5 FOR ["  ARGV[1]  "] <---\n\n"}' \
+   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" 
 fi
@@ -106,7 +109,7 @@ argc=$#
 argv=("$@")
 print=0
 
-while getopts ":e:d:r:n:v:s:f:lo" opt
+while getopts ":e:d:r:n:v:s:f:p:lo" opt
 do
     case "${opt}" in
         s) if [[ -d "${OPTARG}" ]]; then                
@@ -125,11 +128,16 @@ do
         v) value=${OPTARG};;
        r) readUVAR ${OPTARG};;
        l) list;;
-      f) [[ -f $STORE/.uvar_$name ]] && $(rm -f $STORE/.uvar_$name);
+   f) [[ -f $STORE/.uvar_$name ]] && $(rm -f $STORE/.uvar_$name);
       while read line; do 
       echo -e "$line" >> $STORE/.uvar_$name 
       done <${OPTARG}       
       exit;;
+   p) [[ -f $STORE/.uvar_$OPTARG ]] && $(rm -f $STORE/.uvar_$OPTARG);
+      while read value; do 
+      echo -e "$value" >> $STORE/.uvar_$OPTARG;
+      done </dev/stdin
+      exit;;
    d) delUVAR ${OPTARG};;
        o) print="1";;
        e) envnam=$OPTARG