Another way: write your own command launcher. That can just be a basic unix shell, e.g. see here https://www.geeksforgeeks.org/making-linux-shell-c/ or modify bash as I suggest in one of my answers to you below.

Here is a basic command launcher in Perl. WARNING: it is not secure to execute user input!

use strict; use warnings; my ($fh, $cmd); my $cmdI=0; open($fh, '>', 'log.txt'); while(1){ print ++$cmdI."> "; $cmd = <STDIN> || exit; print $fh $cmd; chomp($cmd); # this way you pass your command via the default shell with all the +interpolations happening #system($cmd) && die "failed to run command: $cmd"; # this way you avoid the default shell and launch your perl script d +irectly but # the command line is just one huge parameter (it does not break on +whitespace, like a shell would do) $cmd=~ s/^mycommand\.pl// || die "$0 : your command must always be ' +mycommand.pl'\n"; system('mycommand.pl', $cmd); }
#!perl # mycommand.pl print "got params (number of params: ".@ARGV.") : " . join(' ', @ARGV) +."\n";

It will first log what you wrote without interpolation or checking if quotes balance, etc. Then it can pass what you write to the default shell for interpolating it, breaking it into separate command line arguments and then finally launching your command with these arguments. Or it can pass what you write to the shell your command (which it did launch without a shell - see the array-mode of system()) after it logs it with nothing interpolated. In this way you also get one huge command line parameter because the shell is not invoked in order to interpolate and break it on spaces. You see the shell does (irritating) interpolation but also breaks your parameters into an array to go to ARGV.

bw, bliako

EDIT: don't be scared by the "one huge command line parameter" I mentioned above, because Getopt::Long can parse it as a single string (as opposed to an ARGV-style array, which also does parse really beatifully).


In reply to Re: preserve quotes after $0 + @ARGV interpolation by bliako
in thread preserve quotes after $0 + @ARGV interpolation by richard.sharpe

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.