help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] script with ssh and filenames with spaces


From: Matthew Cengia
Subject: Re: [Help-bash] script with ssh and filenames with spaces
Date: Thu, 18 Jul 2013 22:31:49 +1000
User-agent: Mutt/1.5.21 (2010-09-15)

On 2013-07-18 08:02, Greg Wooledge wrote:
> On Thu, Jul 18, 2013 at 02:04:25PM +1000, Matthew Cengia wrote:
> > I think Greg was probably onto something with his here-doc, but I can't
> > get that to work either.
> 
> Really?  Works for me.
> 
> imadev:~$ ssh vandev bash <<-'EOF'
> >       mkdir "/tmp/foo bar"
> >       ls -ld "/tmp/foo bar"
> >       EOF
> address@hidden's password: 
> mkdir: cannot create /tmp/foo bar: File exists
> -rw-r--r--   1 wooledg    pgmr             0 Aug 22  2002 /tmp/foo bar
> 
> Oops.  I already had a file by that name. ;-)
> 
> What, exactly, did you try, and what was the result?
> 

The OP stored the ls arguments (including the filename with its space)
in an array, and the array expansion isn't happening correctly:

  address@hidden:tmp$ lsargs=(-l -a -r -t "dir with spaces")
  address@hidden:tmp$ ssh toto <<EOF
  ls "address@hidden"
  EOF

  Pseudo-terminal will not be allocated because stdin is not a terminal.
  ls: invalid option -- ' '
  Try `ls --help' for more information.
  address@hidden:tmp$ ssh toto <<EOF
  printf "<%s>\n" ls "address@hidden"
  EOF

  Pseudo-terminal will not be allocated because stdin is not a terminal.
  <ls>
  <-l -a -r -t dir with spaces>
  address@hidden:tmp$ ssh toto <<EOF
  printf "<%s>\n" ls address@hidden
  EOF

  Pseudo-terminal will not be allocated because stdin is not a terminal.
  <ls>
  <-l>
  <-a>
  <-r>
  <-t>
  <dir>
  <with>
  <spaces>

I'm not sure there's a good way to do this.

-- 
Regards,
Matthew Cengia

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]