how to generate random number in this code?
I try use $RANDOM, but the number is still the same. How to improve it?
find . -type f -exec sed -i 's/<field name=\"test/<field name=\"test$RANDOM/g' {} \;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That happens because the
$RANDOMfunction invocation is substituted with its result when you run thefindcommand, not whenfindruns thesedcommand.What you can do is put the
sed -i ...part in a script, and pass this script tofindinstead.For instance, if
subst.shcontains:Then
should do the trick, because
$RANDOMis going to be evaluated as many times as there are files.(Note that the random number will still be the same across one particular file, but it will be distinct for different files.)