I have a shell script that has a on/off switch inside. I programmed the Housekeeping.sh to execute this certain line of code if the value is at 1 and don't execute it if it's at 0. The following is the code on my Housekeeping.sh:
ARCHIVE_SWITCH=1
if [[ $ARCHIVE_SWITCH -eq 1 ]]; then
sqlplus ${BPS_SCHEMA}/${DB_PASSWORD}@${ORACLE_SID} @${BATCH_HOME}/sql/switch_archive.sql
fi
Now I want to create another shell script file that I'll execute to automatically change the variable ARCHIVE_SWITCHequals to 0 everytime I execute this script.
Is there any other way that I can change the value of the variable ARCHIVE_SWITCH from another shell script file that I'll execute manually?
exporttheARCHIVE_SWITCHvariable from the parent shell of each of the two scripts you want to have access to the variable. Generally either create a wrapper script that exports the variables and then starts each shell script in the background, or you can export in your.bashrcand have any script make use of it. (rule a child process may never change the environment of its parent -- so you need the parent to make the environment variable available)sourcefrom that shell.ARCHIVE_SWITCH=1to: ${ARCHIVE_SWITCH=1}. If it's not set in the environment, it will be set to 1. If it is already set in the environment, this will be a no-op.