Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to export value from function to rest of script

Status
Not open for further replies.

dwcasey

MIS
Oct 31, 2002
179
US
I have the following function in a script:
createBackupDir()
{
echo "Type the directory name to create"
read NEWDIR
if [[ -a $MILEAGEHOME/$NEWDIR ]]; then
echo "Directory $NEWDIR exists, try again"
else
mkdir $MILEAGEHOME/$NEWDIR
echo "Created directory $NEWDIR"
fi
read key'?Press Enter to continue ...'
}

How can I export the $NEWDIR variable from this function to the rest of the script so that it can be used after the directory is created?
 
Nothing to do.
You can use the NEWDIR variable in the rest of the script.
If you doesn't declare variable explicitely as local in a function, the variable is global to the script.

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top