illtbagu
asked on
bash if a variable doesn't exit then create it
I am trying to create a script. I need the script to check and see if a variable exists. If the variable does not exist then it needs to create it other wise it can skip this part.
-----------------
if [ -z echo $KDEDIR ]
then
export KDEDIR=/opt/kde3
else
cd $KDEDIR/share/apps/konquer or/service menus/
fi
-----------------
Thanks
-----------------
if [ -z echo $KDEDIR ]
then
export KDEDIR=/opt/kde3
else
cd $KDEDIR/share/apps/konquer
fi
-----------------
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes thats what I was looking for, Thanks. I knew I was kind of close. Can I bother you for one more question? This is really the fist bash script I have wrote and I can't get this part right. I am so use to using windows batch scripting that its killing me. I like batch scripting in windows because I can use the GOTO
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- --
if [ -d /opt/kde3/share/apps/konqu eror/servi cemenus ]
then
echo "Looks Like SuSE."
sleep 1
if [ -z "$KDEDIR" ]
then
echo "Lets create a enviorment varibale for KDE, bad bad SuSE this should have already been done for us."
export KDEDIR=/opt/kde3
if [ -n "$KDEDIR" ]
then
echo "added enviorment variable $KDEDIR"
else
cd $KDEDIR/share/apps/konquer or/service menus/
rm -f shred_files.desktop*
rm -f shred_folders_wrapper.sh*
fi
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- --
--------------------------
if [ -d /opt/kde3/share/apps/konqu
then
echo "Looks Like SuSE."
sleep 1
if [ -z "$KDEDIR" ]
then
echo "Lets create a enviorment varibale for KDE, bad bad SuSE this should have already been done for us."
export KDEDIR=/opt/kde3
if [ -n "$KDEDIR" ]
then
echo "added enviorment variable $KDEDIR"
else
cd $KDEDIR/share/apps/konquer
rm -f shred_files.desktop*
rm -f shred_folders_wrapper.sh*
fi
--------------------------
ASKER
Never mind what I needed was elif.
if [ -z "$KDEDIR" ]
then
export KDEDIR=/opt/kde3
else
cd $KDEDIR/share/apps/konquer
fi
Barry