LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash expert help needed (https://www.linuxquestions.org/questions/programming-9/bash-expert-help-needed-238398/)

illtbagu 10-03-2004 07:56 PM

bash expert help needed
 
This should work but it doesn't
-----------------------------------------------------------------
if [ -d /opt/kde3/share/apps/konqueror/servicemenus ]
then
echo "Looks Like SuSE."
elif [ -z "$KDEDIR" ]
then
export KDEDIR=/opt/kde3
fi
------------------------------------------------------------------

it seems the problem is with
elif [ -z "$KDEDIR" ]
if there was only one condition and this command was instead
if [ -z "$KDEDIR" ]
then it seems to work.
Its just checking to see if the enviorment variable $KDEDIR exist and if it doesn't it creates it.

Thanks for any help,
AD

exodist 10-03-2004 08:44 PM

can we get the terminal output/error messages?

serz 10-03-2004 09:25 PM

Try:

Code:

if [ -d /opt/kde3/share/apps/konqueror/servicemenus ]
then
echo "Looks Like SuSE."
else
if [ -z "$KDEDIR" ]
then
export KDEDIR=/opt/kde3
fi
fi


illtbagu 10-03-2004 09:30 PM

The problem is I am not getting any errors. It seems to just skip the line
if [ -z "$KDEDIR" ]
and anything after it.

see for your self try this
-------------------------------------------------------------------
if [ -d /opt/kde3/share/apps/konqueror/servicemenus ]
then
echo "Looks Like SuSE."
kwrite
elif [ -z "$KDEDIR" ]
then
export KDEDIR=/opt/kde3
kcalc
fi
-------------------------------------------------------------------

illtbagu 10-03-2004 09:48 PM

serz,

Your suggestion didn't work.

Thanks anyways.

Anyone know what is going on?

serz 10-04-2004 12:03 AM

What's the error you're getting?

twantrd 10-04-2004 02:03 AM

Replace '-z' with '-n' and try. Let us know the results.

-twantrd

micxz 10-04-2004 03:54 AM

Re: bash expert help needed
 
Quote:

Originally posted by illtbagu
This should work but it doesn't
-----------------------------------------------------------------
if [ -d /opt/kde3/share/apps/konqueror/servicemenus ]
then
echo "Looks Like SuSE."
elif [ -z "$KDEDIR" ]
then
export KDEDIR=/opt/kde3
fi
------------------------------------------------------------------

I'm no expert but I think you want:

Code:

if [ -d /opt/kde3/share/apps/konqueror/servicemenus ]
then
echo "Looks Like SuSE."
  if [ -z "$KDEDIR" ]
  then
  export KDEDIR=/opt/kde3
  fi
fi


dustu76 10-04-2004 04:55 AM

Original code:
Code:

if [ -d /opt/kde3/share/apps/konqueror/servicemenus ]
then
echo "Looks Like SuSE."
elif [ -z "$KDEDIR" ]
then
export KDEDIR=/opt/kde3
fi

The effect of the above is that if "/opt/kde3/share/apps/konqueror/servicemenus " is found, ALL the other branches are IGNORED (the test for KDEDIR is never done if the directory is found).

You have two requirements:

1. To check whether this is SuSE
2. To check whether KDEDIR is initialised

If these are separate requirements, they don't combine them in the code. In that case all you need is:

Code:

[ -d /opt/kde3/share/apps/konqueror/servicemenus ] && echo "Looks Like SuSE."
[ -z "$KDEDIR" ] && export KDEDIR=/opt/kde3

If you need something else, state exactly what you are trying to do...

HTH.

micxz 10-04-2004 05:40 AM

I think he means if it is suse then set this var. So a embedded condition is needed.

dustu76 10-04-2004 05:55 AM

In that case, the program micxz suggested should work fine.

chrism01 10-04-2004 09:07 AM

Try running it with
set -xv
as the first line, that'll show you exactly what it's doing internally.

illtbagu 10-05-2004 01:07 AM

Thanks very much all of you guys. I am very sorry for getting back to this post so late but I had too much going on : ) , its a Monday.
I have tried all of the suggestions without any luck. I will however go back over all of the post just to make sure. Here is what I am trying to accomplish http://kdelook.org/content/show.php?content=16565
This is going to be revision 0.2 if I can get it to work : )
------------------------------------------------------------------------------
echo "Checking Distro Type..."
sleep 1
if [ -d /usr/share/apps/konqueror/servicemenus ]
then
echo "Looks Like Fedora or Redhat."
sleep 1
fi

if [ -d /opt/kde3/share/apps/konqueror/servicemenus ]
then
echo "Looks Like SuSE."
sleep 1
elif [ -z "$KDEDIR" ]
then
echo "Lets create a enviorment varibale for KDE."
echo "Bad bad SuSE this should have already been done for us."
export KDEDIR=/opt/kde3
elif [ -n "$KDEDIR" ]
then
echo "added enviorment variable $KDEDIR"
fi

cd $KDEDIR/share/apps/konqueror/servicemenus/
rm -f shred_files.desktop*
rm -f shred_folders_wrapper.sh*

sleep 1
echo "...done checking distro type."
echo "...lets start the install."
sleep 1
cat > shred_files.desktop << EOF
[Desktop Entry]
Encoding=UTF-8
ServiceTypes=all/all
Actions=shredfiles;shredfolders
X-KDE-Submenu=Shred Files
X-KDE-Priority=TopLevel
Icon=stop

[Desktop Action shredfiles]
Name=Shred File(s)
Icon=stop
Exec=shred -vfuxz %F

[Desktop Action shredfolders]
Name=Shred Folders(s)
Icon=stop
Exec=$KDEDIR/share/apps/konqueror/servicemenus/shred_folders_wrapper.sh
EOF

cat > shred_folders_wrapper.sh << EOF
#!/bin/bash
#shred files within folders recursivly
if[ -d $1 ]
find $1 -type f -exec shred -vfuxz \{\} \;"
rm -rf $1
else # its a file; just shred it
shred -vfuxz $1
fi
EOF

chmod a+x shred_folders_wrapper.sh

echo "Install Was Successful"
echo "Have Fun"
sleep 3
-----------------------------------------------------------------------------------

dustu76 10-05-2004 01:32 AM

Please go through the thread once again & especially through #8 to #11. Your problem has already been addressed.

HTH.

micxz 10-05-2004 07:26 PM

If your expecting to set the evironment var in the interactive shel you are running. I don't know how this is done.
This quoted from a nblug:

This is a common mistake when writing shellscripts. The script runs in a new instance of the shell which is a child of the interactive shell, and therefore the changes made to the environment don't propagate back up to the parent. If you want the script to run in the current shell, then invoke it like so:

foo@bar:~> . ./script.sh

Or less cryptically:

foo@bar:~> source script.sh

Of course, if your intent is not to modify the environment of the currently running interactive shell, but only to set it up for this script and processes spawned by the script, then the technique you're using will work fine.


All times are GMT -5. The time now is 07:33 AM.