?
Solved

Perplexed with backslashes

Posted on 2003-02-26
6
Medium Priority
?
275 Views
Last Modified: 2010-03-05
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
Comment
Question by:smorehou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 22

Accepted Solution

by:
grg99 earned 120 total points
ID: 8028835
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
 
LVL 2

Expert Comment

by:Itatsumaki
ID: 8028873
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
 

Author Comment

by:smorehou
ID: 8028878
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

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

0
 
LVL 84

Expert Comment

by:ozo
ID: 8029014
Did you try

system "rm -v .ssh/identit*";
0
 

Author Comment

by:smorehou
ID: 8029058
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question