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

  • SEARCH
  • Home
  • 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 4015942
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:40:48+00:00 2026-05-20T09:40:48+00:00

This has been driving me nuts for hours now. Consider the following test script

  • 0

This has been driving me nuts for hours now.

Consider the following test script in perl:
(hello.pl)

#!/usr/bin/perl
print "----------------------------------\n";
$numArgs = $#ARGV + 1;
print "thanks, you gave me $numArgs command-line arguments:\n";

foreach $argnum (0 .. $#ARGV) {
    print "$ARGV[$argnum]\n";
}

Ok, it simply prints out the command line arguments given to the script.

For instance:

$ ./hello.pl apple pie
----------------------------------
thanks, you gave me 2 command-line arguments:
apple
pie

I can give the script a single argument with a space by surrounding the words with double quotes:

$ ./hello.pl "apple pie"
----------------------------------
thanks, you gave me 1 command-line arguments:
apple pie

Now I want to use this script in a shell script. I’ve set up the shell script like this:

#!/bin/bash

PARAM="apple pie"
COMMAND="./hello.pl \"$PARAM\""

echo "(command is $COMMAND)"
$COMMAND

I am calling the hello.pl with the same params and escaped quotes.
This script returns:

$ ./test.sh 
(command is ./hello.pl "apple pie")
----------------------------------
thanks, you gave me 2 command-line arguments:
"apple
pie"

Even though the $COMMAND variable echoes the command exactly like the way I ran the perl script from the command line the second time, this time it does not want to see the apple pie as a single argument.

Why not?

  • 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-20T09:40:49+00:00Added an answer on May 20, 2026 at 9:40 am

    This looks like the problem described in the Bash FAQ as: I’m trying to put a command in a variable, but the complex cases always fail!

    The answer to that FAQ suggests a number of possible solutions – I hope that’s of use.

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

Sidebar

Related Questions

This has been driving me nuts. I keep getting the following exception System.InvalidOperationException: The
This has been driving me nuts for a week now. I have a class
This has been driving me crazy for a few days. Why doesn't the following
This has been driving me nuts. I hope it's not been asked before but
This has been driving me nuts all day. I've seen this problem crop up
This has been driving me nuts all day. I have a weird bug that
This has been driving me nuts, I'm posting here after a lot of looking
This has been driving me nuts for a few days. I am desperate for
This has been driving me absolutely nuts. I have a substitute function like this:
I have a javascript function that has been driving me nuts. This is the

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.