I am writing a Bash script that needs to get part of the current directory path. Let's say the current directory is /cat/dog/bird/mouse/ant. I know that the part that I want is between "bird/" and "/ant". In this case, I would want to set a variable to "mouse".
If the current directory were /cat/dog/bird/giraffe/ant I would want to set a variable to "giraffe" because I want what is between "bird/" and "/ant".
I know that "bird/" and "/ant" are part of the path, but I can't alway predict what will come before that. So, regardless of whether the current directory is /cat/dog/bird/giraffe/ant or /rat/bird/giraffe/ant I want to get the "giraffe" part.
I know I can capture the current directory in my script by doing this: currdir=`pwd`
But I'm not sure what to do afterwards.
I know there is a "cut" command, but that typically works on files, not variables. And I don't know which field number to ask cut to return, because it will vary depending upon what the current directory is.
Would I use awk for this?
Is it frowned upon to use awk within a Bash script? I hesitate to use awk because it seems cleaner to use native Bash rather than embed another whole language in my scripts. What is the conventional wisdom about this? Should I use other languages like awk and Perl in a Bash script? Shouldn't I pick one scripting language and stick to it?