|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
Quote:
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 |
|
#4
|
||||
|
||||
|
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' |
|
#5
|
|||
|
|||
|
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,, |
|
#6
|
||||
|
||||
|
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. |
|
#7
|
|||
|
|||
|
Quote:
thanks so much bro.. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Script must excute on cd |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|