Article 5JE17 Bash substring from the right

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!latest?d=yIl2AUoC8zA latest?i=5r7M8zkxfdA:wW_29y4Esb4:F7zBnMy latest?i=5r7M8zkxfdA:wW_29y4Esb4:V_sGLiP latest?d=qj6IDK7rITs latest?i=5r7M8zkxfdA:wW_29y4Esb4:gIN9vFw5r7M8zkxfdA
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments