[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

shorthand attempt at 'basename file .ext'

From: Linda Walsh
Subject: shorthand attempt at 'basename file .ext'
Date: Tue, 25 Mar 2008 13:51:36 -0700
User-agent: Thunderbird (Windows/20080213)

hey folks, have what is maybe, mostly a mental exercise, but...

forgive me if this is "obvious", but seems I tried this before and
didn't see 'obvious' way to make this work.  "could" be viewed as
a 'bug' (in terms of consistency' maybe?), but, I'd understand that
the design may have been limited to 'simple vars', so in reality,
it would more likely be an RFE.

there may also be a workaround; but workaround wouldn't mean a
"RFE" (or consistency) might not be a good enhancement (fix)...

inputs: f=subpath1/subpath2/myfile.ext  x='.ext'

to get filename (with .ext) I can use
echo "$f" "${f##*/}" (output= subpath1/subpath2/my.file.ext my.file.ext )

the "obvious" next step would be to strip off the ext by using
the tail match and removing that:
echo "${${f##*/}%$ext}" (but: -bash: ${${f##*/}%$ext}: bad substitution)

Then thought..."oh yeah", no "$" before the var being operated on....like
echo "${{f##*/}%$ext}" (but: -bash: ${{f##*/}%$ext}: bad substitution)

Do I need to use an intermediate variable, or is there some construct
that would allow me to do it with no intermediate assign?

"obviously", not a critical problem...but more an "oddity" in that
'obvious' (it would seem to me), way to approach this doesn't work and
it looks like the "var" after ${var...", _maybe_, unnecessarily is
overly restrictive from a semantic point of view (though there may be other
reasons against this type of construct...)

Might be able to come up with a workaround using the substitute operator
with {counts} so as to not swallow more than one {"dot"-ext}, but it
certainly doesn't sound to be 'beautiful'...(sigh)...

just thought that I might find some programs benefiting by not calling
the external /[usr]/bin/{basename,filename} progs...


reply via email to

[Prev in Thread] Current Thread [Next in Thread]