View Full Version : help with a script
chronusdark
March 8th, 2006, 05:24 PM
im new to writing bash scripts and i need to figure out how to loop a command on every file in a directory
and how to put the filename less the extention into a variable
kabus
March 8th, 2006, 05:42 PM
This would put the filename of the first file in a directory into the variable $file and strip off everything after (and including) the last dot in the filename, then repeat the process with the next file until there aren't any files left :
for file in *; do file="${file%.*}"; echo "$file"; done
chronusdark
March 8th, 2006, 05:48 PM
thank you very much
chronusdark
March 8th, 2006, 05:53 PM
one more question how do i add one more character to the end of th $file varible?
hod139
March 8th, 2006, 11:41 PM
one more question how do i add one more character to the end of th $file varible?
I'm not 100% sure what you are asking. If you want to add a new file extension just type:
for file in *; do file="${file%.*}.foo"; echo "$file"; done
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.