* 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
-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.
# 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
#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
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
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