Depending on the shell you're using, you can use Parameter Expansion. For instance in bash
:
${parameter%word}
${parameter%%word}
Remove matching suffix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
a trailing portion of the expanded value of parameter, then the
result of the expansion is the expanded value of parameter with
the shortest matching pattern (the ``%'' case) or the longest
matching pattern (the ``%%'' case) deleted. If parameter is @
or *, the pattern removal operation is applied to each posi‐
tional parameter in turn, and the expansion is the resultant
list. If parameter is an array variable subscripted with @ or
*, the pattern removal operation is applied to each member of
the array in turn, and the expansion is the resultant list.
In your case that would mean doing something like this:
var4=ztemp.xml
var4=${var4%.*}
Note that the character #
behaves in a similar way on the prefix part of the string.
var4=$(echo ztemp.xml | cut -f1 -d '.')
.$(…)
is mostly equivalent to\
…`, except that quoting inside backquotes is peculiar (and in particular nesting backquotes is not recommended), whereas quoting inside
$(…)is unusually intuitive. Furthermore
$(…)is more readable than
`…`which is easily confused with
'…'in many fonts. So if you're going to learn only one, learn
$(…)`. – Gilles 'SO- stop being evil' Dec 06 '10 at 22:25