Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Attempting to have this script run through a directory and perform the operation on every file with the .tmp.tcx extension, so if I had 3 unique files with ${b}.tmp.tcx, I'm hoping for 3 unique files ${b}.tcx.

Unsure why this script ends up only outputting one file in .tcx (line 6). Seems like a problem with line 5 defining b?

#! /bin/bash

for a in *tmp.tcx; do
  if [ -f "$a" ]; then # was it a file
    b="${a%.tmp.tcx}" #set b to $a without .tmp.tcx
    xml fo -t $a > "${b}.tcx"
    mv *gmn /home/pato/garmin/tcx-output/
    mv *tmp.tcx /home/pato/garmin/tcx-output/
share|improve this question
up vote 2 down vote accepted

Your first entry into the loop for the first file does the xml output for the file it finds, then copies all tmp.tcx files out of the folder. So the next go around the loop, the xml will try to process a file that is no longer there.

Try changing line 6 to

 mv $a /home/pato/garmin/tcx-output

Which will only move the file you just processed.

share|improve this answer
perfect - thanks paul – jojo May 21 '12 at 4:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.