LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-03-2004, 07:56 PM   #1
illtbagu
Member
 
Registered: Dec 2002
Location: Nevada
Distribution: fedora, RHEL, ubuntu, suse
Posts: 343

Rep: Reputation: 30
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
 
Old 10-03-2004, 08:44 PM   #2
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Gentoo
Posts: 1,372

Rep: Reputation: 46
can we get the terminal output/error messages?
 
Old 10-03-2004, 09:25 PM   #3
serz
Member
 
Registered: Apr 2003
Location: Buenos Aires, Argentina
Distribution: Slackware, Gentoo
Posts: 397

Rep: Reputation: 30
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
 
Old 10-03-2004, 09:30 PM   #4
illtbagu
Member
 
Registered: Dec 2002
Location: Nevada
Distribution: fedora, RHEL, ubuntu, suse
Posts: 343

Original Poster
Rep: Reputation: 30
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
-------------------------------------------------------------------
 
Old 10-03-2004, 09:48 PM   #5
illtbagu
Member
 
Registered: Dec 2002
Location: Nevada
Distribution: fedora, RHEL, ubuntu, suse
Posts: 343

Original Poster
Rep: Reputation: 30
serz,

Your suggestion didn't work.

Thanks anyways.

Anyone know what is going on?
 
Old 10-04-2004, 12:03 AM   #6
serz
Member
 
Registered: Apr 2003
Location: Buenos Aires, Argentina
Distribution: Slackware, Gentoo
Posts: 397

Rep: Reputation: 30
What's the error you're getting?
 
Old 10-04-2004, 02:03 AM   #7
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
Replace '-z' with '-n' and try. Let us know the results.

-twantrd
 
Old 10-04-2004, 03:54 AM   #8
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
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
 
Old 10-04-2004, 04:55 AM   #9
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
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.
 
Old 10-04-2004, 05:40 AM   #10
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
I think he means if it is suse then set this var. So a embedded condition is needed.
 
Old 10-04-2004, 05:55 AM   #11
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
In that case, the program micxz suggested should work fine.
 
Old 10-04-2004, 09:07 AM   #12
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,287

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
Try running it with
set -xv
as the first line, that'll show you exactly what it's doing internally.
 
Old 10-05-2004, 01:07 AM   #13
illtbagu
Member
 
Registered: Dec 2002
Location: Nevada
Distribution: fedora, RHEL, ubuntu, suse
Posts: 343

Original Poster
Rep: Reputation: 30
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
-----------------------------------------------------------------------------------
 
Old 10-05-2004, 01:32 AM   #14
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

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

HTH.
 
Old 10-05-2004, 07:26 PM   #15
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
expert help needed with bash and bc karistouf Programming 5 06-22-2005 12:55 AM
X11 Expert Needed hilltop*Tech Linux - Hardware 4 06-10-2005 09:11 AM
Expert help with iptables needed k1mgy Linux - Networking 2 08-01-2004 07:21 AM
Fdisk Expert !! Badly needed mickeyboa Fedora 1 07-18-2004 08:52 PM
Security Expert needed Lloydlec Linux - Security 1 04-27-2004 11:45 AM


All times are GMT -5. The time now is 09:19 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration