UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 3rd, 2006, 05:08 AM
mani_um mani_um is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 12 mani_um User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 24 m 33 sec
Reputation Power: 0
Script must excute on cd

hi guyz,
i am new in Unix..i am using unix ibm
i dunno much abt script,,now in process of learning,
i need to execute certain files on change directory(cd) for example

if i am in path /home/mani/devl/test1/ and subfolders then i need SRC_ROOT as this
$SRC_ROOT=/home/mani/devl

if i am in path /home/mani/devl/test2/ and subfolders then i need SRC_ROOT as this
$SRC_ROOT=/home/subramani/devl

so anyone can help me in script plz..
thanks in advance

Reply With Quote
  #2  
Old October 3rd, 2006, 07:36 AM
mu's Avatar
mu mu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Dublin, Ireland
Posts: 174 mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 39 m 56 sec
Reputation Power: 39
Hi,

The following code should do what you're looking for.

Code:
#!/usr/bin/bash

path=`pwd`

if [ `echo $path | grep '/home/mani/devl/test1'` ]; then
        export SRC_ROOT=/home/mani/devl
elif [ `echo $path | grep '/home/mani/devl/test2'` ]; then
        export SRC_ROOT=/home/subramani/devl
fi

cd $@


In order to execute it you'll have to source it

Code:
. ~/scripts/cd.sh /path/to/some/dir


Set up an alias for it so that you don't have to source it everytime you want to use it.

Code:
alias d='. ~/scripts/cd.sh'


Then you can use the command d as you would use cd.

Reply With Quote
  #3  
Old October 3rd, 2006, 09:13 PM
mani_um mani_um is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 12 mani_um User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 24 m 33 sec
Reputation Power: 0
Quote:
Originally Posted by iota
Hi,

The following code should do what you're looking for.

Code:
#!/usr/bin/bash

path=`pwd`

if [ `echo $path | grep '/home/mani/devl/test1'` ]; then
        export SRC_ROOT=/home/mani/devl
elif [ `echo $path | grep '/home/mani/devl/test2'` ]; then
        export SRC_ROOT=/home/subramani/devl
fi

cd $@


In order to execute it you'll have to source it

Code:
. ~/scripts/cd.sh /path/to/some/dir


Set up an alias for it so that you don't have to source it everytime you want to use it.

Code:
alias d='. ~/scripts/cd.sh'


Then you can use the command d as you would use cd.




Thank you very much bro...i will try it,,just wanna ask u something,, is tht any what to do tht in makefile itself,how to do it in makefile itself so tht we gmake in certain folder means it will run the script and change the SRC_ROOT as we want,
any idea bro..
thanks for ur kindness

Reply With Quote
  #4  
Old October 4th, 2006, 08:29 AM
mu's Avatar
mu mu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Dublin, Ireland
Posts: 174 mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 39 m 56 sec
Reputation Power: 39
If I'm understanding you correctly, you want to change SRC_ROOT when you run gmake?

Modify the script, remove the cd command from the last line

Code:
#!/usr/bin/bash

path=`pwd`

if [ `echo $path | grep '/home/mani/devl/test1'` ]; then
        export SRC_ROOT=/home/mani/devl
elif [ `echo $path | grep '/home/mani/devl/test2'` ]; then
        export SRC_ROOT=/home/subramani/devl
fi


Create your alias again

Code:
alias srcroot='. ~/scripts/srcroot.sh'


Then I suppose you couldcreate a gmake alias:

Code:
alias gmake='srcroot; gmake'

Reply With Quote
  #5  
Old October 4th, 2006, 10:57 PM
mani_um mani_um is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 12 mani_um User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 24 m 33 sec
Reputation Power: 0
thank you so much bro..
i am so glad to know u....
thanks,,it works great as i want..
ok bro wanna ask one question...the first script u give got this command line

cd $@

what tht mean.... after we do alias let say d

then,

d /path/to/change

so tht means $@ is input izit....
and if its input it should be in first line rite,,
coz in first like ur command is

path=`pwd`
if [ `echo $path | grep '/home/ednms/' ` ]; then
export SRC_ROOT=/home/ednms/ednms05/

tht means pwd shows current path and assign it to path
tht means before we change directory it will show the path where we type tht command rite
let say
from
/home# d /home/endms

so accoding to the script it must run pwd first so tht
inside path only /home
so how it will grep /home/ednms/
but ur code works find,,i am confuse,,
maybe it wil run command first the only will continue if statment,,??
coz its in last statment
sorry if i trouble u sir,,

Reply With Quote
  #6  
Old October 5th, 2006, 06:28 AM
mu's Avatar
mu mu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Dublin, Ireland
Posts: 174 mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 39 m 56 sec
Reputation Power: 39
Code:
#!/usr/bin/bash

# store the result of executing pwd in
# the path variable

path=`pwd`

# if the $path variable contains the string
# /home/mani/devl/test1,

if [ `echo $path | grep '/home/mani/devl/test1'` ]; then
        
        # set the SRC_ROOT variable to /home/mani/devl
        
        export SRC_ROOT=/home/mani/devl

# if the $path variable contains the string
# /home/mani/devl/test2,

elif [ `echo $path | grep '/home/mani/devl/test2'` ]; then

         # set the SRC_ROOT variable to /home/subramani/devl

        export SRC_ROOT=/home/subramani/devl
fi

# pass the arguments passed to the script
# to the cd command, this means that if you typed
# d /etc, it will execute cd /etc. I guess I could have 
# just used cd $1, to reference the first argument 
# passed to the script, but I wasn't sure at the 
# time if the cd command could take any other
# arguments

cd $@


Hope that helps.

Reply With Quote
  #7  
Old October 5th, 2006, 08:32 PM
mani_um mani_um is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 12 mani_um User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 24 m 33 sec
Reputation Power: 0
Quote:
Originally Posted by iota
Code:
#!/usr/bin/bash

# store the result of executing pwd in
# the path variable

path=`pwd`

# if the $path variable contains the string
# /home/mani/devl/test1,

if [ `echo $path | grep '/home/mani/devl/test1'` ]; then
        
        # set the SRC_ROOT variable to /home/mani/devl
        
        export SRC_ROOT=/home/mani/devl

# if the $path variable contains the string
# /home/mani/devl/test2,

elif [ `echo $path | grep '/home/mani/devl/test2'` ]; then

         # set the SRC_ROOT variable to /home/subramani/devl

        export SRC_ROOT=/home/subramani/devl
fi

# pass the arguments passed to the script
# to the cd command, this means that if you typed
# d /etc, it will execute cd /etc. I guess I could have 
# just used cd $1, to reference the first argument 
# passed to the script, but I wasn't sure at the 
# time if the cd command could take any other
# arguments

cd $@


Hope that helps.


thanks so much bro..

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Script must excute on cd


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT