本脚本的目的是,让sftp命令启动时,看起来和ftp一模一样。就是输入用户,远程地址等内容。
#!/bin/sh
# mysftp.sh -- make sftp start up more like ftp
echo -n "User account: "
read account
if [ -z "$account" ]; then
exit 0;
fi
if [ -z "$1" ]; then
echo -n "Remote host: "
read host
if [ -z "$host" ]; then
exit 0
fi
else
host=$1
fi
exec /usr/bin/sftp -C $account@$host
运行结果:
$ mysftp
User account: taylor
Remote host: intuitive.com
Connecting to intuitive.com...
taylor@intuitive.com's password:
sftp> quit
$ mysftp intuitive.com
User account: taylor
Connecting to intuitive.com...
taylor@intuitive.com's password:
sftp> quit
这个脚本中,唯一需要注意的技巧是最后一行的exec命令。它会用指定的应用来代替当前正在运行的shell。因为,你知道在调用了sftp命令后就可以结束了,那么这种方法的效果是要好于将shell挂起等待,直到sftp命令执行完毕。