If there is a space in the file name when scp is performed in expect bash, it is treated as a different file.

Asked 2 years ago, Updated 2 years ago, 78 views

If the file name is space separated when scp is performed with bash expect, it will be treated as a different file.

fromfile='[email protected]:/tmp/hoge hhoge hhoge.txt'
expect-c"
set timeout 3600
spawn env LANG = C/usr/bin/scp${fromfile}${encdir}${ori_file}
expect\"password:\"
send\"${PW}\n\"
expect\"$\"
exit0
"

This is the same with (ya) and [ya].You need to escape once, but even if you escape as above, you will still be treated as a different file and get an error.

If you know how to deal with it, please let me know.

bash expect

2022-09-30 19:34

2 Answers

Comments

Even if scp [email protected]: 'hoge hoge.txt' test.txt with shell command, hoge
and hoge.

If is correct,

export FROMFILE='[email protected]:"/tmp/hoge hoge.txt"'
export ENCDIR='...'
export ORI_FILE='...'
export PW = '...'
expect-c'
  set timeout 3600
  spawn env LANG = C/usr/bin/scp "$env(FROMFILE)" "$env(ENCDIR)$env(ORI_FILE)"
  expect"\[Pp\]assword:"
  send -- "$env(PW)\n"
  expect "$"
  exit0
'

Is it? As you can see in https://stackoverflow.com/questions/19858176/how-to-escape-spaces-in-path-during-scp-copy-in-linux, I think I need to escape or quote double.

Quotation processing will be difficult if you do not pass various variables as environment variables instead of embedding them as bash variables in the expect script.

2017-03-14 Additional note: I was regularly told to evaluate someone, so I added consideration to the quota process so that I wouldn't be ashamed of myself.Added consideration when the password starts with -.


2022-09-30 19:34

You can use {file1,file2...} to specify a list of spaces and files instead:

fromfile='[email protected]:\{/tmp/hoge ,,/tmp/hoge.txt,hoge ,,hoge.txt\}'

This link and From this link, to copy multiple files:

$scp [email protected]:/some/remote/directory/\{a,b,c\}.
$ scp [email protected]: ~/\{foo.txt, bar.txt\}.


2022-09-30 19:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.