Bash substring from the right
by TBotNik from LinuxQuestions.org on (#5JE17)
All,
I know in BASH you can extract a substring from the right using something similar to the following:
Code:mystr="filepath/filename.ext"
slen=${mystr}
rstr=${mystr:$slen:-4}
echo "L=> $slen R=> $rstrMy code is supposed to pick off the extension in the string.
I'm having a syntax error here so I've looked for examples of this and found none, so asking about my syntax here and a good link to examples.
Also there is another my to extract the ext by finding the index for the "." and pulling the substring from there.
All help appreciated!
Cheers!
TBNK
PS
Oh! Remembered there is also a set of functions that pull:
1.) path (directory),
2.) base (filename),
3.) ext.
But I forgot those also!


I know in BASH you can extract a substring from the right using something similar to the following:
Code:mystr="filepath/filename.ext"
slen=${mystr}
rstr=${mystr:$slen:-4}
echo "L=> $slen R=> $rstrMy code is supposed to pick off the extension in the string.
I'm having a syntax error here so I've looked for examples of this and found none, so asking about my syntax here and a good link to examples.
Also there is another my to extract the ext by finding the index for the "." and pulling the substring from there.
All help appreciated!
Cheers!
TBNK
PS
Oh! Remembered there is also a set of functions that pull:
1.) path (directory),
2.) base (filename),
3.) ext.
But I forgot those also!