This question already has an answer here:

I Would like to automate the process to install the managed packages in scratch orgs so that I dont need to install the packages every time I create the scratch org for development. Any script or process that can provide solution to my problem, please let me know. Thanks!

marked as duplicate by sfdcfox, Oleksandr Berehovskyi, Mr.Frodo, David Reed, Derek F Jun 15 '18 at 13:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.