Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Perplexed with backslashes

I'm trying to run some code in perl under cygwin...

$sshpath=".ssh\\identit*";   # 2 backslashes-one escapes the other
@args=("rm", "-v", "$sshpath");
system(@args);


As it is here, the output is ".ssh\\identity* doesn't exist"  (notice it iterpreted it as 2 backslashes)

So then I thought, "oh, i guess with system() I don't need to escape my backslash"

So then I tried:

$sshpath=".ssh\identit*"

and now my output is ".sshidentity* doesn't exist"

!!!!!!

So when I DO escape the backslash, it treats it as two backslashes and when I don't escape the backslash, it treats it as no backslashes????

How do I get ONE backslash????

Thanks
0
smorehou
Asked:
smorehou
1 Solution
 
grg99Commented:
The problem might be you are unnecessarily quoting the use of $sshpath.  Just change this line to:

@args=("rm", "-v", $sshpath );


... and it just might work better.
0
 
ItatsumakiCommented:
I don't have an explanation of that behaviour, but I do have a solution:
$sshpath= '.ssh\identit*';
should work fine....
And if you really need to concatenate variable you can do:
$sshpath = '.ssh\'.$whatever;

Also, I agree with grg99 that you don't need to quote $sshpath in @args.
0
 
smorehouAuthor Commented:
Thanks.  That didn't make a difference.

What's more... if I declare the variable as:

$sshpath='.ssh\identit*';

using single quotes, it still puts the output as having two backslashes.

Ok... alternative...
does anyone know how to "cd" through perl in cygwin???

If I can change the current directory to .ssh before running the command I wouldn't have to worry about this quirk.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
smorehouAuthor Commented:
my above reply was to grg99. Itatsumaki posted at same time as me.  However, I addressed the single quote suggestion ;)

0
 
ozoCommented:
Did you try

system "rm -v .ssh/identit*";
0
 
smorehouAuthor Commented:
Ok... i figured it out

it had to do with rm... not perl

When i did a simple print of the output, it was giving the expected .ssh\ident* (with a single \)

That got me thinking that it was actually escaping the backslash within rm for some crazy reason.

Anyway... in case this goes into the archives and some poor sap happens upon the same problem...

I was using the rm.exe that came with the cygwin distribution:

rm (fileutils) 4.1
Written by Paul Rubin, et al.

I went and found a different version:

rm (GNU fileutils) 3.16

and it works just fine.  Or at least it doesn't screw with my backslashes (it may have other bugs I'm not yet aware of).

Thanks for your help

grg99 gets the points for pointing out my sloppy over-quoting :)

Thanks all
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now