1

If I have a file called test.php and its contents are

$a = "apple";    
echo PHP_EOL;
echo "  the value of \$a is $a" . PHP_EOL;

I want to cat the contents of test.php to STDOUT but I want to add a header string <?php to the beginning of the output. My desired outcome is to run a command like

% cat ..... test.php

desired output in terminal

<?php
$a = "apple";    
echo PHP_EOL;
echo "  the value of \$a is $a" . PHP_EOL;

I have tried assigning the string <?php to a variable and concatenating the variable with a here-string, e.g.

% php='<?php'       
% cat <<<$php
<?php
% cat <<<$php test.php 
$a = "apple";
echo PHP_EOL;
echo "  the value of \$a is $a" . PHP_EOL;

When I try to concatenate a here-string to a file the here-string is ignored.
How can I insert a header into the STDOUT before the cat'ed file?

1 Answers1

3

Why not simply use the proper commands:

echo "<?php" && cat test.php
  • 1
    the reason I didn't use this form is because - once I got this command working - I then wanted to attach the STDOUT to a pipe. But I just tried your command wrapped in command group brackets and it works with a pipe, e.g. { echo "<?php" && cat test.php; } | php thanks – the_velour_fog May 14 '16 at 00:27
  • @the_velour_fog: My pleasure! :) – Julie Pelletier May 14 '16 at 00:37