|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
search a string for a character
Hello people,
I have variable that contains a path address of sorts, as seen below. What i need to do, if possible, is to search the string from the end to find the last '/' character and then delete everything that comes after the / So i would start with: MY_PATH=./tools/calculator and then finish up with: MY_PATH=./tools/ How could this be done? Cheers Mike |
|
#2
|
|||
|
|||
|
man basename
and man dirname
__________________
working on Solaris[5-9], preferred languages french and C. |
|
#3
|
|||
|
|||
|
Ok cheers mate i've got it working now
Thanks for pointing me in the right direction Mike... |
|
#4
|
|||
|
|||
|
Quote:
Hi, very useful but very rarely used technique is the notation ${variable#pattern} ${variable##pattern} ${variable%pattern} ${variable%%pattern} The pattern can be anything legal in shell script, i. e. variable reference or output of a command etc. So this method is not limited to the patterns starting with a slash. Try this: : A=X/aaa/bbb/ccc echo 1. ${A%/*} echo 2. ${A%%/*} echo 3. ${A#X*/} echo 4. ${A##X*/} Have a fun ![]() |
|
#5
|
|||
|
|||
|
do not insist
Quote:
you still insist a well known shell is running try to be a little more 'portable' |
|
#6
|
|||
|
|||
|
Quote:
Well yes guggach, I am trying to help people even if they do not specify their interpreter. So I usualy specify the interpreter I am using. This time I have forgotten to do so. Can you forgive it to me? My present script was tested under ksh or bash on AIX, HP-UX, Linux and SCO. Are you satisfied with it? And what YOU are doing for the people who need help? Regards |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > search a string for a character |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|