BASH rename .log to .LOG

I am having a hard time understanding this. I have researched brace expansion and the mv command but for some reason it still isn't making sense to me. I am reading Unix and Linux system administration handbook and they use this as an example, but I'm not understanding the line:

mv $fname ${fname/.log/.LOG};

I realize it is moving the current $fname variable which is anything with .log but the ${fname/.log/.LOG}; is confusing me. I thought it was basically mv source destination... So why are there 2 /'s? If someone could explain this to me in plain english I would be most appreciative!

#!/bin/bash

find . -type f -name '*.log' | grep -v .do-not-touch | while read fname;
do
mv $fname ${fname/.log/.LOG/};
done

Answers


The mv line should be interpreted as "Move $fname to ${fname/.log/.LOG}". The ${var/pattern/string} construct is one form of the Parameter Expansion called Pattern Substitution. It returns the variable's value with the first occurrence of the pattern replaced by the string. In other words, it replaces .log with .LOG in this case. Therefore, for each file, the line is something like

mv file.log file.LOG

Need Your Help

Shoulda: Testing contoller filters

ruby-on-rails integration-testing filter shoulda

So I have decided to investigate the state of Rails' testing. After reading a few accepted answers here on SO talking about how Rails' testing documentation is atrocious I am starting to agree. Thu...

tesseract-ocr how to includ baseapi.h

c++ visual-studio-2010 api ocr tesseract

I followed the instructions I found in form of tessesract on how to includ baseapi.h.