Re: A quick Q: how do I command something in large amount
>>>>> Axel Freyn <axel-freyn@gmx.de> writes:
[…]
> So you should try e.g.
> for FILE in *.txt; do mv "$FILE" "`basename \"$FILE\" .txt`".pdf; done
Backticks are obsolete for a long time, and that's precisely the
reason. Consider how much cleaner is the following:
for FILE in *.txt; do mv "$FILE" "$(basename "$FILE" .txt)".pdf; done
Furthermore, Bash also allows one to spare a basename(1)
invocation, like:
for FILE in *.txt; do mv "$FILE" "${FILE%.txt}".pdf; done
Finally, I'd like to make a few more changes:
(for file in *.txt; do mv -- "$file" "${file%.txt}".pdf; done)
It is left as an exercise to the reader to figure out the
differences between the two.
> (this works at least with spaces in the filename...)
The last command above should work for any valid filename.
--
FSF associate member #7257 2 days left to Software Freedom Day
http://sf-day.org/ Event at Altai State University: http://sfd.am-1.org/
Reply to: