找不到Spawn命令

Phi*_*Phi 3 bash shell command expect spawn

我尝试运行.sh文件时出错

line 2: spawn: command not found
": no such file or directory
bash.sh: line 3: expect: command not found
bash.sh: line 4: send: command not found
#!/usr/bin/expect -f
spawn sftp -o IdentityFile=MyFile.ppk 500200243@XXX.XXX.XXX.XXX
expect "XXX.XXX.XXX.XXX.gatewayEnter passphrase for key 'MyFile.ppk.ppk':"
send "myPassword"
Run Code Online (Sandbox Code Playgroud)

知道为什么会这样吗?

gle*_*man 8

  1. 这是一个期望脚本,所以".exp"将是一个合适的文件扩展名: mv bash.sh sftp.exp
  2. 不要像bash bash.sh或那样启动它sh bash.sh.做这个:
    1. 使程序可执行: chmod a+x sftp.exp
    2. 使用./sftp.exp/path/to/sftp.exp将其移动到$ PATH中的目录并使用它启动它sftp.exp
  3. 在你send "myPassword"必须"击中回车"之后:send "myPassword\r"
  4. 在开发期望计划时,添加exp_internal 1到顶部.

祝你好运,并回来再提问.