Shell variable values are transient when used from script! [solved!]
Posted: Mon Aug 31, 2020 9:22 am
Hello Puppians! Woof!:
I asked this Q before, got an answer on the murga forum but can't find it.
I want to learn how to use variables in a script.
The problem: I assign a value to a variable and when I use the variable inside the script: bingo! The variable works. (example shown below)
When I use the same variable from the keyboard the variable is 'gone'.
cobaka.
Examples below:
First - the script. I call it vdf.sh (variable definition file - shell script)
Clearly, the defined variable has a transient life. It exists only until the end-of-shell file marker.
PLEASE HELP ME UNDERSTAND WHY THIS IS SO. I know there reason for this and a solution.
cobaka
I asked this Q before, got an answer on the murga forum but can't find it.
I want to learn how to use variables in a script.
The problem: I assign a value to a variable and when I use the variable inside the script: bingo! The variable works. (example shown below)
When I use the same variable from the keyboard the variable is 'gone'.
cobaka.
Examples below:
First - the script. I call it vdf.sh (variable definition file - shell script)
I run the script. You can see it work:#!/bin/sh
# file name: variable definition file, vdf.sh
# contains variable definitions used when grepping and awking text transcript.
# file location /root/my-applications/bin.
echo 'this script defines string variables: '
sdpa=/root/my-applications/bin # script directory path
echo 'printing script directory path:'
echo $sdpa
echo
echo 'and now: I define the path to transcript text folder'
ttPa=/mnt/sda1/Law/bNgo/transcript/text
ls $ttPa
cd $ttPa; echo
pwd
echo '(end of script file).'
When I list the folder (or directory) from the keyboard I get a completely different result. I see the content of the root directory.# vdf.sh
defining variables from a script file:
printing script directory path:
/root/my-applications/bin
and now: I define the path to transcript text folder
1t-text a_ht_grep.txt int-afm.txt tmp_al3t.txt wit-1t.txt
2t-text cm-text nq-text wd.txt wit_list_cm.txt
3t-text --color pt-text wit-1tB.txt wtbc-1tB.txt
/mnt/sda1/Law/bNgo/transcript/text
(end of script file).
OMG! The value of the string has changed! Life isn't worth living!# ls $ttPa
95-99 Downloads my-applications scr V_16-26.mp4 wla.txt
95-99-tmp exhi-a my-documents spot V_16-29+.mp4 wl.txt
bin ex-tmp network Startup V_16-47.mp4
Choices File-Sharing one_GiB Templates V_16.mp4
d35+99 ftpd ot-fil tmpp V_IG.mp4
Desktop grefil puppy-reference V_15-54.mp4 Web-Server
# pwd
/root
#
Clearly, the defined variable has a transient life. It exists only until the end-of-shell file marker.
PLEASE HELP ME UNDERSTAND WHY THIS IS SO. I know there reason for this and a solution.
cobaka