linux - 在循环内调用 sftp 脚本时循环退出

标签 linux bash shell unix

我编写了一个名为 process.sh 的 shell 脚本,它在循环内调用 sftp 脚本 del.sh。但是一旦调用 sftp 脚本(del.sh),它就不会返回到 process.sh

进程.sh

<小时/>
#!/bin/bash
for i  in $(ls *.csv)
do
 fbname=$(basename "$i" .csv)
echo "$fbname"
if [ -f $fbname.done ]
then
gzip $fbname.csv
exec /home/amithsa/del.sh $fbname.csv 
else
echo "File Not Found"
fi
done;

del.sh

<小时/>
#!/usr/bin/expect
set arg1 [lindex $argv 0]
spawn sftp xyz@10.10.10.10 22
expect "password:" 
send "xxxxxxxxx\n" 
expect "sftp>"
send "cd sftp\n"
expect "sftp>"
send "rm $arg1\n"
expect "sftp>"
send "rm *.html\n"
expect "sftp>"
send "exit\n"
interact

最佳答案

如果您希望脚本继续运行,请不要使用execexec 将用您给出的命令完全替换当前进程。它永远不会返回1

只需像调用 gzipecho 以及其他命令一样调用脚本即可,即直接调用。

gzip $fbname.csv
/home/amithsa/del.sh $fbname.csv 

1 除非该命令无法执行,并且您启用了 execfail 选项。或者您正在运行交互式 shell。

关于linux - 在循环内调用 sftp 脚本时循环退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28022837/

相关文章:

bash - : (colon) GNU Bash builtin? 的目的是什么

linux - 在 bash 中使用单引号仍然给出 "event not found"

c - linux c 中的 sendmsg() 调用出错

bash - 使用 bash 搜索并替换特定行

c - 我的 shell 中的连接运算符 ";"无法正常工作

linux - 打开新的 shell session 时,我的 Bash 脚本不响应 SIGNALS

linux - 预计无法在我的 Bash 脚本中运行

c++ - 记录数据时磁盘写入延迟

linux - 递归覆盖bash中的rc文件

bash - bash中的 `declare -r`和 `readonly`有什么区别?