Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Double backslash behavior not as expected (http://www.velocityreviews.com/forums/t902937-double-backslash-behavior-not-as-expected.html)

alt.testing@{g}mail.com 05-04-2007 02:06 AM

Double backslash behavior not as expected
 
Hi all,
the simple concept of escaping a "backslash", thus translating to a
literal backslash; does not provide the implied result, under the
following example.

$mount_result = qx#strace /bin/mount -t smbfs \\\\$machine\\documents
/mnt/workstation_shares/$mount/documents/ -o ro -o username=$user -o
password=$pass#;

The top part of the "strace" output gives this:

execve("/bin/mount", ["/bin/mount", "-t", "smbfs", "\\an2documents",
"/mnt/workstation_shares/xxxx/doc"..., "-o", "ro", "-o",
"username=xxxx", "-o", "password=xxxxxxxxxx"], [/* 22 vars */]) = 0

"\\an2documents"

Note; that there is no "\" in between the machine name, and the share.
It should be "\\an2\documents".

[root@mercedes sbin]# perl -e 'print "\\\\an2\\documents\n"'
\\an2\documents


I'm sure it's a simple thing, but can someone enlighten me on this
parlay?

ta.



Full Context
================================================== =============================


#!/usr/bin/perl

use strict;
use warnings;

my $input_vars_file = "/usr/local/etc/priv/users_test";
my $tmp_vars;
my $input_vars;
my @input_vars_array;
my @target_vars_array;

my $user;
my $pass;
my $machine;
my $mount;
my $mount_result;

open ( IN_FILE, "< $input_vars_file") or die "$!";

while ( <IN_FILE> ){
$tmp_vars = $_;
$tmp_vars =~ s/(\s+)/,/g;
$tmp_vars =~ s/;.*$//g;
@input_vars_array = split( /,/, $tmp_vars );
push @target_vars_array, [ @input_vars_array ] unless ( /^\W/ );
}
close IN_FILE;

for my $counter ( 0 .. $#target_vars_array ) {

$user = $target_vars_array[$counter][0];
$pass = $target_vars_array[$counter][1];
$machine = $target_vars_array[$counter][2];
$mount = $target_vars_array[$counter][3];

print "$user, $pass, $machine, $mount\n";
$mount_result = qx#/bin/mount#;

if ( $mount_result =~ /$machine\/documents/ ) {
print "$machine: already mounted\n";
}
else {
$mount_result = qx#strace /bin/mount -t smbfs \\\\$machine\\documents
/mnt/workstation_shares/$mount/documents/ -o ro -o username=$user -o
password=$pass#;
}

print "$mount_result\n";

}

exit

John W. Krahn 05-04-2007 02:44 AM

Re: Double backslash behavior not as expected
 
alt.testing@{g}mail.com wrote:
> Hi all,
> the simple concept of escaping a "backslash", thus translating to a
> literal backslash; does not provide the implied result, under the
> following example.
>
> $mount_result = qx#strace /bin/mount -t smbfs \\\\$machine\\documents
> /mnt/workstation_shares/$mount/documents/ -o ro -o username=$user -o
> password=$pass#;
>
> The top part of the "strace" output gives this:
>
> execve("/bin/mount", ["/bin/mount", "-t", "smbfs", "\\an2documents",
> "/mnt/workstation_shares/xxxx/doc"..., "-o", "ro", "-o",
> "username=xxxx", "-o", "password=xxxxxxxxxx"], [/* 22 vars */]) = 0
>
> "\\an2documents"
>
> Note; that there is no "\" in between the machine name, and the share.
> It should be "\\an2\documents".
>
> [root@mercedes sbin]# perl -e 'print "\\\\an2\\documents\n"'
> \\an2\documents
>
>
> I'm sure it's a simple thing, but can someone enlighten me on this
> parlay?


Your string is interpolated twice, once by perl and then by the shell.

$ perl -le'
$machine = "an2";
$mount = "xxxx";
print qx#echo /bin/mount -t smbfs
\\\\$machine\\documents/mnt/workstation_shares/$mount/documents/#;
'
/bin/mount -t smbfs \an2documents/mnt/workstation_shares/xxxx/documents/


You need to double up on the back-slashes.

$ perl -le'
$machine = "an2";
$mount = "xxxx";
print qx#echo /bin/mount -t smbfs
\\\\\\\\$machine\\\\documents/mnt/workstation_shares/$mount/documents/#;
'
/bin/mount -t smbfs \\an2\documents/mnt/workstation_shares/xxxx/documents/





John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall

alt.testing@{g}mail.com 05-04-2007 03:13 AM

Re: Double backslash behavior not as expected
 
On Fri, 04 May 2007 02:44:00 GMT, "John W. Krahn"
<someone@example.com> wrote:

>alt.testing@{g}mail.com wrote:
>> Hi all,
>> the simple concept of escaping a "backslash", thus translating to a
>> literal backslash; does not provide the implied result, under the
>> following example.
>>
>> $mount_result = qx#strace /bin/mount -t smbfs \\\\$machine\\documents
>> /mnt/workstation_shares/$mount/documents/ -o ro -o username=$user -o
>> password=$pass#;
>>
>> The top part of the "strace" output gives this:
>>
>> execve("/bin/mount", ["/bin/mount", "-t", "smbfs", "\\an2documents",
>> "/mnt/workstation_shares/xxxx/doc"..., "-o", "ro", "-o",
>> "username=xxxx", "-o", "password=xxxxxxxxxx"], [/* 22 vars */]) = 0
>>
>> "\\an2documents"
>>
>> Note; that there is no "\" in between the machine name, and the share.
>> It should be "\\an2\documents".
>>
>> [root@mercedes sbin]# perl -e 'print "\\\\an2\\documents\n"'
>> \\an2\documents
>>
>>
>> I'm sure it's a simple thing, but can someone enlighten me on this
>> parlay?

>
>Your string is interpolated twice, once by perl and then by the shell.
>
>$ perl -le'
>$machine = "an2";
>$mount = "xxxx";
>print qx#echo /bin/mount -t smbfs
>\\\\$machine\\documents/mnt/workstation_shares/$mount/documents/#;
>'
>/bin/mount -t smbfs \an2documents/mnt/workstation_shares/xxxx/documents/
>
>
>You need to double up on the back-slashes.
>
>$ perl -le'
>$machine = "an2";
>$mount = "xxxx";
>print qx#echo /bin/mount -t smbfs
>\\\\\\\\$machine\\\\documents/mnt/workstation_shares/$mount/documents/#;
>'
>/bin/mount -t smbfs \\an2\documents/mnt/workstation_shares/xxxx/documents/
>


Thanks John,
Nick



>
>
>John



Martijn Lievaart 05-04-2007 05:45 AM

Re: Double backslash behavior not as expected
 
On Fri, 04 May 2007 02:44:00 +0000, John W. Krahn wrote:

> Your string is interpolated twice, once by perl and then by the shell.
>
> $ perl -le'
> $machine = "an2";
> $mount = "xxxx";
> print qx#echo /bin/mount -t smbfs
> \\\\$machine\\documents/mnt/workstation_shares/$mount/documents/#; '
> /bin/mount -t smbfs \an2documents/mnt/workstation_shares/xxxx/documents/
>
>
> You need to double up on the back-slashes.


Or use forward slashes. That also works for smb paths with smbmount and
this shows why....

HTH,
M4

Dan Mercer 05-04-2007 01:19 PM

Re: Double backslash behavior not as expected
 

"John W. Krahn" <someone@example.com> wrote in message news:Q5x_h.1690$Vi6.1400@edtnps82...
: alt.testing@{g}mail.com wrote:
: > Hi all,
: > the simple concept of escaping a "backslash", thus translating to a
: > literal backslash; does not provide the implied result, under the
: > following example.
: >
: > $mount_result = qx#strace /bin/mount -t smbfs \\\\$machine\\documents

Use:
$mount_result = qx#strace /bin/mount -t smbfs '\\\\$machine\\documents'

which the shell will see as '\\an2\documents'

Dan Mercer


: > /mnt/workstation_shares/$mount/documents/ -o ro -o username=$user -o
: > password=$pass#;
: >
: > The top part of the "strace" output gives this:
: >
: > execve("/bin/mount", ["/bin/mount", "-t", "smbfs", "\\an2documents",
: > "/mnt/workstation_shares/xxxx/doc"..., "-o", "ro", "-o",
: > "username=xxxx", "-o", "password=xxxxxxxxxx"], [/* 22 vars */]) = 0
: >
: > "\\an2documents"
: >
: > Note; that there is no "\" in between the machine name, and the share.
: > It should be "\\an2\documents".
: >
: > [root@mercedes sbin]# perl -e 'print "\\\\an2\\documents\n"'
: > \\an2\documents
: >
: >
: > I'm sure it's a simple thing, but can someone enlighten me on this
: > parlay?
:
: Your string is interpolated twice, once by perl and then by the shell.
:
: $ perl -le'
: $machine = "an2";
: $mount = "xxxx";
: print qx#echo /bin/mount -t smbfs
: \\\\$machine\\documents/mnt/workstation_shares/$mount/documents/#;
: '
: /bin/mount -t smbfs \an2documents/mnt/workstation_shares/xxxx/documents/
:
:
: You need to double up on the back-slashes.
:
: $ perl -le'
: $machine = "an2";
: $mount = "xxxx";
: print qx#echo /bin/mount -t smbfs
: \\\\\\\\$machine\\\\documents/mnt/workstation_shares/$mount/documents/#;
: '
: /bin/mount -t smbfs \\an2\documents/mnt/workstation_shares/xxxx/documents/
:
:
:
:
:
: John
: --
: Perl isn't a toolbox, but a small machine shop where you can special-order
: certain sorts of tools at low cost and in short order. -- Larry Wall




All times are GMT. The time now is 06:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.