shell - How to store a user password using BASH script and access it in scripts it invokes -


i have script:

setup.sh

read -s -p "enter password use in script: " password  echo -e $password | sudo -s brew cask install junk  echo "done installing junk, running step 1..." ./step1.sh 

step1.sh

echo -e $password | sudo -s some-other-command 

obviously $password empty in step1.sh, , export variable use globally in other scripts invokes:

export password 

or can use script argument:

setup.sh

read -s -p "enter password use in script: " password  echo -e $password | sudo -s brew cask install junk  echo "done installing junk, running step 1..." ./step1.sh $password 

step1.sh

echo -e $1 | sudo -s some-other-command 

i'm assuming first example using export isn't idea security perspective (however, i'm not sure). second usable , secure? also, if not, there better way without relying on sudo caching password (i have large list of scripts take time execute , cache timeout , want entire script unattended)?

don't send/use password plaintext.

run first script sudo first.sh , privilege drop (if needed) inside script, call second script first script.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -