You could use mktemp
:
$ mktemp foobarXXXXXX
foobarAU7TyS
$ mktemp foobarXXXXXX
foobardDqS61
$ mktemp foobarXXXXXX
foobarioCZw2
In your example perhaps that would be something like:
mv "$fname" "$(mktemp "${fname%.zip}"XXXXXX.zip)"
But you should do some testing. Strange things happen for zipfiles that end with 'X'... ;) (needs a non-X suffix/separator which I've conveniently left out in this example).
The nice thing about mktemp
is that it makes sure, no matter how unlikely the chance may be, that the filename did not already exist. Of course it's useless in the example above that does not check for errors in the first place...
Or you make use of mv
's builtin --backup
mechanism.
(Depends on why you are doing this in the first place.)
"$(mktemp "${fname%.zip}"XXXXXX)".zip
instead? (Sorry, I kinda missed the OSX part of your question :) – frostschutz Feb 28 '17 at 11:45