Suppose I run the following commands:
export STR="abcdef.ghijkl.mnopqr.stuvwy.log"
echo $STR | sed 's/\.[^.]*$//'
I am getting the following result:
abcdef.ghijkl.mnopqr.stuvwy
Please help me understand the above result.
Suppose I run the following commands:
I am getting the following result:
Please help me understand the above result. |
||||
Your sed pattern Details:
So here the final
|
|||||||||
|
|
|||
|
If you don't want to use
See Shell-Parameter-Expansion in the BASH man page for more information. |
||||
|
echo $STR
mangles your string, you're lucky here that it doesn't contain any special characters and so escapes unscathed. Always put double quotes around substitutions:echo "$STR"
. This can still mangle an initial-
; it's best to useprintf '%s\n' "$STR"
, or here use shell string operations and avoid these difficulties. – Gilles Aug 3 '11 at 23:57