tags:

views:

48

answers:

3

I'm trying to create a Makefile that uses information from the path to create a relevant rpm name. Suppose I have two different possible paths:

PATH1 = /usr/local/home/jsmith/code/main
PATH2 = /usr/local/home/jsmith/code/dev/ver2

If "main" is detected in the path, I want to detect and append "main" to the rpm name. If "dev" is detected in the path, I want to detect and append "ver2" to the rpm name.

I'm new to shell scripting and really don't have a good idea on where to start. I could easily do this in something like python, but its for a Makefile so I need to do it in shell.

"main" in the path would be constant, but if "main" doesn't exist, the dev path name would need to be extracted. Here's a few mow examples:

/usr/local/home/jsmith/code/main /usr/local/home/jsmith/code/dev/ver_usa /usr/local/home/jsmith/code/dev/ver_mexico /usr/local/home/jsmith/code/dev/ver3

If "dev" existed, it would be needed to extract "ver_usa", "ver_mexico", "ver3", etc. The dir name needing to be extracted would exactly follow "dev".

A: 

Use grep and check for return value?

Also, you can run python in Makefile.

Kimvais
+1  A: 

something like this, assuming "main" and "ver2" are not constant

some_rpm_name="some rpm"
PATH=/usr/local/home/jsmith/code/main
#PATH2=/usr/local/home/jsmith/code/dev/ver2
s=${PATH##*/}
case "$s" in
  *main ) RPM_NAME="${some_rpm_name}_main";;
  *ver2) RPM_NAME="${some_rpm_name}_ver2";;
esac
echo $RPM_NAME
ghostdog74
I added more detail to the question. "ver2" wouldn't necessarily be constant, but would need to be extracted and would exist following "../dev/"
ok, so they are not constant. see my edit.
ghostdog74
A: 

It looks like the last element of the path is always the one you want.

rpmname=$rpmname+${pathname##*/}

or

rpmname=$rpmname+$(basename pathname)
Dennis Williamson