I understand the modifiers # ## % %%, but I can't figure out if its possible to chain them together as you can in tcsh.
Example in tcsh
set f = /foo/bar/myfile.0076.jpg
echo $f:r:e
--> 0076
echo $f:h:t
--> bar
In bash, I'd like to know how to do something like:
echo ${f%.*#*.}
in one line.
My goal is to be able to manipulate filenames in various ways as and when needed on the command line. I'm not trying to write a script for one specific case. So if there is a way to chain these modifiers, or maybe there's another way, then I'd love to know. Thanks
I found a solution that gets pretty close to the simplicity of the tcsh filename modifiers. I wrote 4 functions and put them in .bashrc.
Definitions are at the end.
These functions can accept an argument like so:
or accept input from a pipe, which is the feature from tcsh that I really wanted:
or of course, a combination:
and it just dawned on me it will accept many files through the pipe:
Definitions: