I know that I can remove substrings from the front of a variable:
X=foobarbaz
echo ${X#foo} # barbaz
...and from the back of a variable:
echo ${X%baz} # foobar
How do I combine the two? I've tried:
echo ${{X#foo}%baz} # "bad substitution"
echo ${${X#foo}%baz} # "bad substitution"
echo ${X#foo%baz} # foobarbaz
I don't think I can use an intermediate variable, because this is being used in find -exec
, in something like the following:
find ./Source -name '*.src' \
-exec bash -c 'myconvert -i "{}" -o "./Dest/${0#./Source/%.src}.dst"' {} \;
expr "foobarbaz" : 'foo\(.*\)baz$'
returns the captured "bar". – meuh yesterday