我在看一些老shell脚本和有一条线,我不太明白这样做:是什么-b选项在SFTP
~]$ sftp -b /dev/fd/3 [email protected]
我可以从该名男子看到文件 - b用于批处理,并且该参数应该是批处理文件。
在这种情况下,它看起来像批处理文件应该在/ dev/fd/3上 - 一个软盘驱动器?我似乎无法做到。
任何想法这应该做什么?
我在看一些老shell脚本和有一条线,我不太明白这样做:是什么-b选项在SFTP
~]$ sftp -b /dev/fd/3 [email protected]
我可以从该名男子看到文件 - b用于批处理,并且该参数应该是批处理文件。
在这种情况下,它看起来像批处理文件应该在/ dev/fd/3上 - 一个软盘驱动器?我似乎无法做到。
任何想法这应该做什么?
"/dev/fd*"
文件是特殊设备。这些并没有真正占用您系统上的太多空间。它们允许进程通过数字访问文件描述符; 0,1,2
是标准input
,standard output
和standard error
,等打开的文件开始3
在你的情况sftp
使用-b
从/dev/fd/3
读取示例命令:
[[email protected] fd]# exec 3< /etc/resolv.conf
[[email protected] fd]# cat /dev/fd/3
search example.com
nameserver 10.10.10.10
nameserver 20.20.20.20
可以使用read
读取数据命令
[[email protected] fd]# read -u 3 a b
[[email protected] fd]# echo $a $b
nameserver 10.10.10.10
输出/dev/fd
directoy
[[email protected] fd]# ls -l /dev/fd/
total 0
lrwx------ 1 root root 64 Feb 20 14:34 0 -> /dev/pts/0
lrwx------ 1 root root 64 Feb 20 14:34 1 -> /dev/pts/0
lrwx------ 1 root root 64 Feb 20 14:34 2 -> /dev/pts/0
lr-x------ 1 root root 64 Feb 20 14:34 3 -> /etc/resolv.conf
注意事项:在你的情况下输入文件可以是不同的
/dev/fd
实际上并不是软盘驱动器 - “fd”代表“文件描述符”。在终端中尝试man fd
。
本页概述了发生了什么事情:http://lists.apple.com/archives/darwinos-users/2004/Apr/msg00042.html。基本上,SFTP写入的第一个文件(可能是它下载的文件?)将作为批处理文件传回给自己。
没有看到整个脚本或知道SFTP的内部,我无法确切地知道发生了什么。我猜想脚本连接到的服务器上有一个文件列表,而/ dev/fd/3用于让SFTP下载列表,然后下载文件而不重新连接。