This is a puzzle of a cross-domain fashion in multiple environments.
Problem: an Perl installation script that installs a Perl program that auto-starts at boot, and can be started or stopped from the command line. In any release of RHEL, CentOS, Debian, Ubuntu, or Kali.

I have found a bash script that seems to reliably identify 'system5-init', 'upstart', and 'systemd' as foundations for process control. Running the script in back-ticks has interpretation problems. Using 'system' will only return the exit value, not the STDOUT (which is possibly usable, but rather opaque).

#create the bash script to determine whic Init System my $tmpScript = "/tmp/whichSysInit"; my $whichInit = <<"END"; #!/bin/bash if [[ `/sbin/init --version 2>/dev/null` =~ upstart ]]; then echo using upstart; elif [[ `systemctl` =~ -\.mount ]]; then echo using systemd; elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]; then echo using sysv-init; else echo cannot tell; fi END open OPT, "> $tmpScript"; print OPT $whichInit; close OPT; chmod 0555, $tmpScript; #run that script to get answer my $rslt= `$tmpScript`; #unlink $tmpScript; # cleanup print " Initialization is $rslt\n"; #react to the result #if ($rslt =~/using\s(?<si>\S+)/){ # my $sysInit= $+{si};
When I run the file left in /tmp/ from the command line, it echos the appropriate string.
When run the file in back-ticks the following errors are produced:
/tmp/whichSysInit: 2: /tmp/whichSysInit: [[: not found /tmp/whichSysInit: 1: /tmp/whichSysInit: systemctl: not found /tmp/whichSysInit: 4: /tmp/whichSysInit: [[: not found /tmp/whichSysInit: 6: /tmp/whichSysInit: [[: not found Can not determine System Init mechanism <>. Exiting
I searched for the program '[[', but none was found.
Linux ubuntu 3.11.0-26-generic #45~precise1-Ubuntu SMP Tue Jul 15 04:02:35 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

The shell in the environmant is '/bin/bash'
Maybe the '#!' on line 1 isn't run? And bash isn't what is interpreting the script?
Thoughts?

It is always better to have seen your target for yourself, rather than depend upon someone else's description.


In reply to Back-ticks and bash by Wiggins

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.