quoting @ARGV items back could be a challenge only when they are quoted. Otherwise quote them with single quotes, since bash had already interpolated anything that should had been interpolated.

In the case there are quotes, I have not given it too much thought, but this can quote back your command line to equivalent effect to the original (but not the same):

print join ' ', ($0, map { qw/$'/ . s/'/\\'/gr . qw/'/ } @ARGV);

Assuming bash. If you find you need a lot of tweaking and extra cases handling then the path you are following is the wrong one and you probably do not need the actual command line verbatim.

btw, $0 holds your command and @ARGV your command arguments.

bw, bliako

p.s. at the time of writing this, ikegami suggested something more robust because it uses an existing module (with probably all the edges covered). What the heck! Every time a one-liner is thrown away a sailor is drowned in the high seas, so here you go.


In reply to Re: preserve quotes after $0 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.