Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: @ARGV ignores quotes (updated)

by AnomalousMonk (Archbishop)
on Jun 19, 2021 at 17:56 UTC ( [id://11134030]=note: print w/replies, xml ) Need Help??


in reply to @ARGV ignores quotes

... if there is quotes inside the job part, it will remove those quotes.

Command line arguments are processed first by the command line interpreter (CLI) of the OS you're using, the "shell', e.g., sh, bash, etc. (I'm assuming you're running under *nix). It is the OS CLI that's "removing" quotes before Perl ever sees the command line arguments. E.g., your command line might have been
    my_script.pl '--option1' '--option2' '--job' 'some_job.pl' '-option1' 'some_job2.pl -x abc' '-option2'
and the @ARGV dump from within Perl would have been exactly the same. (Update: For example, here's something from Windoze — I don't have access to *nix ATM:

Win8 Strawberry 5.8.9.5 (32) Sat 06/19/2021 14:21:47 C:\@Work\Perl\monks >perl -MData::Dump -e "print qq{>$_< } for @ARGV" -- foo bar "baz \"ba +ff\" zip" >foo< >bar< >baz "baff" zip< Win8 Strawberry 5.8.9.5 (32) Sat 06/19/2021 14:23:37 C:\@Work\Perl\monks >perl -MData::Dump -e "print qq{>$_< } for @ARGV" -- "foo" "bar" "baz +\"baff\" zip" >foo< >bar< >baz "baff" zip<
This even has escaped double-quotes embedded in one of the arguments. As you can see, the strings derived from the command line arguments are exactly the same within Perl.)

Why do you need to know if a command line argument was originally quoted or not? (Update: IOW, why not just assume that all the command line options were quoted. What difference would it make?) This sounds very much like an XY problem.

I want to get user's command and execute it at some point. It could have parameters and I don't want the user to insert it into file first.

I don't understand what you are trying to do here and what problem you're trying to overcome.


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134030]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found