Sample Script for Installing Second-Generation Managed Packages with Dependencies
Use this sample script as a basis to create your own script to install second-generation managed packages with dependencies. This script contains a query that finds dependent packages and installs them in the correct dependency order.
Be sure to replace the package version ID and scratch org user name with your own specific details.