If the goal is to have a PHP file where you can insert CSS into the header of all pages then what you need is a plugin, one of your own creation, not one you install.
Create a .php
file in the plugins folder, e.g. templaters-plugin.php
and insert this:
<?php
/*
Plugin name: Templaters test plugin
*/
Then you can add PHP to that file.
If you want to add arbitrary HTML to a location then you’ll need to use filters. Not using filters will break stuff in weird and unexpected ways, which is very bad for your stated goal of learning PHP.
For example, you can use the WordPress APIs to enqueue a CSS file, or add inline scripts, but you can also add HTML to the header, e.g.:
add_action( 'wp_head', function() {
echo '<!-- I appear in the head tag -->';
} );
As for your stated goal of injecting PHP into a file via bash, this won’t work, and can never work. The problem is WordPress is a CMS, it has systems and ways of doing things, so there is no “last PHP file” to inject your code into, it’s a dynamic system not a chain of files executed in a specific order. Even then, WordPress has shutdown handlers, so even if you did manage to locate a last file for a specific path, it’s no guarantee that other code won’t run anyway.
The irony is, the closest thing to what you wanted, is the very thing you said you did not want, a theme template. A theme of your own creation that only contained an index.php
fits 99% of all your requirements, and in a lot of cases is indeed the last file processed. You could put the entire HTML structure in one file, and experiment to your hearts content in an environment that behaves more like a classic PHP application, including appending to it with a bash file if you so chose.