First off: generally, BUT ESPECIALLY IN SHELLSCRIPTING it helps if you tell us which shell you use and ideally which system you use.
There are several things wrong with this:
for i in ./*.txts* or ./*.log*
A for-loop doesn't work in shell like in other languages: it is given a list of distinct values and the loop-variable takes one after the other value in each pass. In light of this: ./*.txts*
will be expanded by the shell prior to executing the loop to a list of filenames fitting the pattern. In this case every file in the currecnt directory which name contains the string ".txts". Then it will add "or" to the list. At last it will expand ./*.log*
. So finally, after the expansion, you have a statment like:
for i in ./foo.txtsx ./bar.txtsy or ./foo.logx ./whatever.logbla
and these values will be assigned consecutively to "$i". This is presumably not what you want, yes? What you perhaps want is a list of files ending either in ".txts" or in ".log". This would look like this (notice that i took the trailing asterisk out, so now it will match "file.log" but not "file.log.old"):
for i in ./*.txts ./*.log
The next issue is this command:
mv -- "$i" "${i//.txts/-s}"
The expansion ${i//.txts/-s}
says: take the content of "$i", replace every occurrence of ".txts" and replace it with "-s", then display the result. So the above-mentioned example "./foo.txtsx" will become "./foo-sx" and the resulting command would be:
mv -- "./foo.txtsx" "./foo-sx"
Furthermore the files named "*.log*" will probably be unchanged at all because they probably will not contain the string ".txts" in their names. If they do a possible result would look like:
mv -- "./foo.txtsx.logbar" "./foo-sx.logbar"
Which, i suppose, is also not what you want.
One last point, but this is not a show-stopper: i suggest you format your for-loops differently so that they are easier to read:
for var in <LIST> ; do
command "$var"
done
This way the command stands out and it is easy to see where the loop starts and ends.
Baseline is: tell us in clear-text what you want to do and we can probably better correct your code.
I hope this helps.
bakunin