Let’s say you have a given directory with possible configurations and you want to create a environment file for your laravel app. Within this directory are several .php files containing things like this:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Application Name
    |--------------------------------------------------------------------------
    |
    | This value is the name of your application. This value is used when the
    | framework needs to place the application's name in a notification or
    | any other location as required by the application or its packages.
    |
    */

    'name' => env('APP_NAME', 'Laravel app'),

    /*
    |--------------------------------------------------------------------------
    | Application Environment
    |--------------------------------------------------------------------------
    |
    | This value determines the "environment" your application is currently
    | running in. This may determine how you prefer to configure various
    | services your application utilizes. Set this in your ".env" file.
    |
    */

    'env' => env('APP_ENV', 'production'),

A proper environment file would look like this:

APP_NAME=Laravel App
APP_ENV=production

We have to grep through all .php files, search for only UPPER_CASE strings and write them into a new file called ‘environment’:

% grep -oP '\b[A-Z_]*[A-Z]+[A-Z_]*\b' *.php
app.php:APP_NAME
app.php:APP_ENV

Which is fine if you want to start from scratch or want to build a example file with a lot of comments. As you can see, every line contains the source file. Turn this off with ‘-h’

% grep -h -oP '\b[A-Z_]*[A-Z]+[A-Z_]*\b' *.php
APP_NAME
APP_ENV