Wise PerlMonks, I consider myself a novice at perl and I am in need of some assistance. I have an issue with regards to executing an alias from Perl. I have a script that that keeps track of my inputs in a file. When'-c' is inputed it should ask for a command, write the command to the file, execute command and write the output to the file as well. Then it should return back to the loop.

 `$cmd` was working fine for build in commands, but would not execute alias commands. I read that I would need to use the command

 `bash -c -i "$cmd"` This fixed the kinda fixed the problem, except it would exit the program and not reenter the loop.

Is there any way to run an alias command and continue with the rest of the code?

Here is the section of my code that is at fault:
if($input eq "-c"){ print "Enter Command: "; my $cmd = <STDIN>; print $fh $cmd; print $fh "\n\t#### START COMMAND OUTPUT ####\n"; print `bash -c -i "$cmd"`; foreach(`bash -c -i "$cmd"`){ print $fh "#".$_; } print $fh "\t#### END COMMAND OUTPUT ####\n"; next; }
Thank you in advance.


In reply to How to execute alias commands by nanophd

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.