本脚本的目的是,让sftp命令启动时,看起来和ftp如出一辙。就是输入用户,远程地址等内容。 shell
#!/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命令执行完毕。