Double backslash behavior not as expected

A

alt.testing

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
 
J

John W. Krahn

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
 
A

alt.testing

alt.testing@{g}mail.com said:
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
 
M

Martijn Lievaart

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
 
D

Dan Mercer

: 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top