1

I am trying to run a bsub command from a perl script in the following way:

system ("bsub -select "testid::1" -q normal");

but I think perl is getting confused because of the double quotes in "testid::1". What is the proper way to implement this?

tripleee
  • 175,061
  • 34
  • 275
  • 318
ibrahim
  • 45
  • 4
  • 1
    Change either the outer or inner quotes to single quotes: `'` – Hunter McMillen Aug 20 '14 at 13:13
  • Hi @HunterMcMillen, Thanks for your reply. But I have a more complicated problem. My bsub command also has a single quote so it looks like:system ('bsub 'select[type==LINUX64&&clearcase]'-select "testid::1" -q normal'); – ibrahim Aug 20 '14 at 13:19

2 Answers2

6

You can escape the inner quotes:

system ("bsub -select \"testid::1\" -q normal");

or replace the outer quotes with single quotes, or in fact any character at all, thanks to the qq generalized quote operator in Perl which exists precisely for this sort of scenario;

system (qq{bsub -select "testid::1" -q normal});

There is a companion generalized single quote operator q.

Miller
  • 34,962
  • 4
  • 39
  • 60
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 1
    Yes, to using `qq`. But a big no to using relatively obscure delimiters like "^". What's wrong with `qq( ... )`? – Dave Cross Aug 20 '14 at 13:53
  • 1
    That's fine and probably an improvement. I was just demonstrating that you can really use any character at all. – tripleee Aug 20 '14 at 14:02
1

Rather than fitting the entire command in a single quoted string (although using the generalized quoting operators makes that fairly simply), you can use the multi-argument version of system to avoid needing to quote the entire command line.

system 'bsub', 'select[type==LINUX64&&clearcase]', '-select', 'testid::1', '-q' 'normal';
chepner
  • 497,756
  • 71
  • 530
  • 681