Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>cat</code> copies its inputs unchanged to its outputs - at least in its original (1st Edition UNIX) form. It didn't have any options to start with. Then BSD added a bunch, and the original UNIX team objected: '<code>cat</code> came back from Berkeley waving flags' (see: <a href="http://simson.net/ref/ugh.pdf" rel="nofollow">1</a> - passim). It should not be used to edit files - that is not its purpose. (I found a reference to the article in the BSD (Mac OS X) man page for <code>cat</code>: Rob Pike, <em>"UNIX Style, or cat -v Considered Harmful"</em>, USENIX Summer Conference Proceedings, 1983. See also <a href="http://quotes.cat-v.org/programming/" rel="nofollow">http://quotes.cat-v.org/programming/</a>)</p> <p>So, you need something other than <code>cat</code> to do the job. I'd recommend Perl or Python; either can do it pretty easily. Alternatively, consider <code>sed</code>, or perhaps <code>awk</code>.</p> <pre><code>#!/usr/bin/env perl use strict; use warnings; while (&lt;&gt;) { foreach my $key (keys %ENV) { s/\$$key\b/$ENV{$key}/g; # $envvar s/\${$key}/$ENV{$key}/g; # ${envvar} } print; } </code></pre> <p>This loops through the input line, looking for each environment variable in turn. The alternative mechanism is to look for possible variables and do the relevant substitution. This turns out to be a little tricky, but doable:</p> <pre><code>#!/usr/bin/env perl use strict; use warnings; while (&lt;&gt;) { while (m/\$((\w+))/ || m/\$({(\w+)})/) { my $key = $2; my $var = $1; s/\$$var/$ENV{$key}/g if defined $ENV{$key}; } print; } </code></pre> <p>When I included the literal <code>$</code> in the captures, the substitute operation did not work correctly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload