I would like to add text to the end of filename but before the extension. Right now I am trying,
for f in *.shp; do echo $f_poly; done
the output is,
Quercus_acutifolia.shp_poly
Quercus_agrifolia.shp_poly
Quercus_corrugata.shp_poly
Quercus_cortesii.shp_poly
Quercus_costaricensis.shp_poly
Quercus_havardii.shp_poly
Quercus_hemisphaerica.shp_poly
Quercus_kelloggii.shp_poly
Quercus_knoblochii.shp_poly
Quercus_laceyi.shp_poly
I want it to be,
Quercus_acutifolia_poly.shp
Quercus_agrifolia_poly.shp
Quercus_corrugata_poly.shp
Quercus_cortesii_poly.shp
Quercus_costaricensis_poly.shp
Quercus_havardii_poly.shp
Quercus_hemisphaerica_poly.shp
Quercus_kelloggii_poly.shp
Quercus_knoblochii_poly.shp
Quercus_laceyi_poly.shp
printf
with a format string instead of the less portableecho
. 2. I use parameter expansion which is more efficient than calling an external binary (basename
) for such a simple task. – jw013 Jun 23 '15 at 14:43for f in *.shp; do mv $f ${f%.shp}_poly.shp; done
– Patch92 Feb 13 '19 at 12:28printf
required here? If not, using it instead of theecho
makes the answer more confusing than it needs to be. The little gained in portability (echo
is ubiquitious nowadays) is lost in comprehensibility for novices. – Hashim Aziz Nov 27 '20 at 05:49