Re: Double backslash behavior not as expected




"John W. Krahn" <someone@xxxxxxxxxxx> wrote in message news:Q5x_h.1690$Vi6.1400@xxxxxxxxxxx
: 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


.



Relevant Pages

  • Re: Unexpected result from grep
    ... I'd worry about whether I should be using the shell at all. ... as big a deal as Perl. ... Most people can puzzle out even a complicated shell script and also ... seem to prefer ksh and it sure seems like a better shell to me. ...
    (comp.unix.tru64)
  • Re: Unexpected result from grep
    ... I'd worry about whether I should be using the shell at all. ... as big a deal as Perl. ... Most people can puzzle out even a complicated shell script and also ... seem to prefer ksh and it sure seems like a better shell to me. ...
    (comp.unix.shell)
  • Re: ActiveState: Cant spawn "cmd.exe"?
    ... >> When testing with ActiveState perl what shell are you running in? ... Normally, perl is built using MinGW in the cmd.exe shell, following the ... ActiveState perl, too) in a bash shell, though I've not personally done ...
    (comp.lang.perl.misc)
  • shell power vs. modern GUI IDE
    ... I think that the power of shell programming (particularly with the use ... scripting + perl with programming with IDEs like Eclipse or NetBeans. ... Perhaps one problem in vim is the source code browsing: ...
    (de.comp.os.unix.programming)
  • Re: how to easily determine shell script is running in background from within script
    ... That's not really the shell. ... That's the exit status of commands. ... process group of the terminal is the process' process group, ... There are a number of perl functions in the POSIX ...
    (comp.unix.shell)