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 |
can we get the terminal output/error messages?
|
Try:
Code:
if [ -d /opt/kde3/share/apps/konqueror/servicemenus ] |
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 ------------------------------------------------------------------- |
serz,
Your suggestion didn't work. Thanks anyways. Anyone know what is going on? |
What's the error you're getting?
|
Replace '-z' with '-n' and try. Let us know the results.
-twantrd |
Re: bash expert help needed
Quote:
Code:
if [ -d /opt/kde3/share/apps/konqueror/servicemenus ] |
Original code:
Code:
if [ -d /opt/kde3/share/apps/konqueror/servicemenus ] 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." HTH. |
I think he means if it is suse then set this var. So a embedded condition is needed.
|
In that case, the program micxz suggested should work fine.
|
Try running it with
set -xv as the first line, that'll show you exactly what it's doing internally. |
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 ----------------------------------------------------------------------------------- |
Please go through the thread once again & especially through #8 to #11. Your problem has already been addressed.
HTH. |
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. |