Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6381265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:22:27+00:00 2026-05-25T02:22:27+00:00

I am getting some perl compile errors trying to convert these unix commands to

  • 0

I am getting some perl compile errors trying to convert these unix commands to perl.
The use of single quotes and double quotes is throwing me off (see below: my $curlcmd).

Here’s the working unix commands executed in order:

export CERT=`/dev/bin/util --show dev.testaccnt | awk '{print $2}'`

/usr/bin/curl -c /home/foobar/cookee.txt --certify /dev/key.crt \
     --header "FooBar-Util:'${CERT}'" \
     https://devhost.foobar.com:4443/fs/workflow/data/source/productname?val=Summ

I want to do the same within Perl:

#Build cmd in perl
my $cookie='/home/foobar/cookee.txt';
my $certkey='/dev/key.crt';
my $fsProxyHostPort='devhost.foobar.com:4443';
my $fsPath='workflow/data/source/productname';
my $fsProxyOperation='Summ';
my $fsProxyURL="https://$fsProxyHostPort/fs/$fsPath?val=$fsProxyOperation";

#Get cert
my $cert=qx(/dev/bin/pass-util --show foobar.dev.testaccnt | awk '{print \$2}');

Here’s where I am having trouble executing it:

my $curlcmd = qx(/usr/bin/curl -c $cookie --certify $certkey --header "FooBar-Util:'${" . $cert . "}'". $fsProxyURL);

Can someone show me how to setup these commands in Perl correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:22:28+00:00Added an answer on May 25, 2026 at 2:22 am

    In the shell script, you have (in part):

    --header "FooBar-Util:'${CERT}'"
    

    This generates something like:

    --header FooBar-Util:'data-from-certificate'
    

    where the curl command gets to see those single quotes. To get the same result in Perl, you will need:

    my $header = "FooBar-Util:'$cert'";
    my $out = qx(/usr/bin/curl -c $cookie --certify $certkey --header $header $fsProxyURL);
    

    Changes:

    • Lost the ${ ... } notation.
    • Lost the concatenation operations.

    In situations where you have problems seeing the argument list sent to a command, I recommend using a program analogous to the shell echo command, but which lists each argument on its own line, rather than as a space-separated set of arguments on a single line. I call my version of this al for ‘argument list’. If you test your commands (for example, the shell version) by prefixing the whole command line with al, you get to see the arguments that curl would see. You can then do the same in Perl to compare the arguments curl sees at the shell with the ones given it by Perl. Then you can fix the problems, typically much more easily.

    For debugging with al:

    my @lines = qx(al /usr/bin/curl -c $cookie --certify $certkey --header $header $fsProxyURL);
    foreach my $line (@lines) { print "$line"; }
    

    If you want to write al in Perl:

    #!/usr/bin/env perl
    foreach my $arg (@ARGV) { print "$arg\n"; }
    

    Adventures in Validating an Answer

    Fortunately, I usually check what I write as answers – and what is written above is mostly accurate, except for one detail; Perl manages to invoke the shell on the command, and in doing so, the shell cleans out the single-quotes:

    my $cert = 'certificate-info';
    my $fsProxyURL = 'https://www.example.com/fsProxy';
    my $cookie = 'cookie';
    my $certkey = 'cert-key';
    my $header = "FooBar-Util:'$cert'";
    #my @out = qx(al /usr/bin/curl -c $cookie --certify $certkey --header $header $fsProxyURL);
    my @cmdargs = ( 'al', '/usr/bin/curl', '-c', $cookie, '--certify', $certkey, '--header', $header, $fsProxyURL);
    print "System:\n";
    system @cmdargs;
    print "\nQX command:\n";
    my @lines = qx(@cmdargs);
    foreach my $line (@lines) { print "$line"; }
    

    This yields:

    System:
    /usr/bin/curl
    -c
    cookie
    --certify
    cert-key
    --header
    FooBar-Util:'certificate-info'
    https://www.example.com/fsProxy
    
    QX command:
    /usr/bin/curl
    -c
    cookie
    --certify
    cert-key
    --header
    FooBar-Util:certificate-info
    https://www.example.com/fsProxy
    

    Note the difference in the `FooBar lines!

    At this point, you start to wonder what’s the least unclean way to work around this. If you want to use the qx// operator, then you probably do:

    my $header = "FooBar-Util:\\'$cert\\'";
    

    This yields the variant outputs (system then qx//):

    FooBar-Util:\'certificate-info\'
    
    FooBar-Util:'certificate-info'
    

    So, the qx// notation now gives the single quotes to the executed command, just as in the shell script. This meets the goal, so I’m going to suggest that it is ‘OK’ for you; I’m just not sure that I’d actually adopt it in my own code, but I don’t have a cleaner mechanism on hand. I’d like to be able to use the system plus ‘array of arguments’ mechanism, while still capturing the output, but I haven’t checked whether there’s a sensible (meaning relatively easy) way to do that.

    One other passing comment; if any of your arguments contained spaces, you’d have to be excruciatingly careful with what gets passed through the shell. Having the al command available really pays off then. You can’t identify which spaces in echo output are parts of one argument and which are separators provided by echo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using some system commands in Perl. In the below case I was getting
I am getting some errors thrown in my code when I open a Windows
I'm getting some really wierd linking errors from a class I wrote. I am
I currently have some code which returns a sites header content back: #!/usr/bin/perl use
I've been trying to code a Perl script to substitute some text on all
I am getting some very annoying behaviour from my perl cgi scripts running under
I have a few lines of text that I'm trying to use Perl's split
I wrote a perl script which uses some linux commands ( grep , ls
I am trying to convert the use of @ARGV with using Getopt::Std instead in
I am having some difficulties getting results from a form via Perl. I believe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.