bash脚本中的通配符

bash脚本中的通配符

本文介绍了bash脚本中的通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,可以从ftp检索文件.

I have a bash script to retrieve files from ftp.

现在,文件中的文件名中一部分包含日期字符串,但每个文件上都有未定义的数字.我想根据日期下载文件.

Now the files have one part a date string in the filename, but also undefined numbers that changes on every file. I want to download the files based on the date.

这是我的代码.我只需要做通配符就可以了,ftp脚本已经可以使用了.

This is my code. I only need to do the wildcard trick, the ftp script is allready work.

filename=$(echo $TIMESTAMP'0***vel.radar.h5')

星星是我无法估计的3位数字,因此我将对它们使用通配符.

The stars are 3 digits with different numbers that i can't estimate, so i would use the wildcard for them.

谢谢

推荐答案

听起来您想处理多个文件,但是您的脚本一次只能处理一个文件.此外,由于您指定了FTP,因此听起来文件位于FTP服务器上,在这种情况下,本地文件名扩展将无济于事.

It sounds like you want to handle multiple files, but your script can only handle one file at a time. Furthermore, because you specified FTP, it sounds like the files are on the FTP server, in which case local filename expansion will not help.

您可能想使用ftp客户端的 mget 命令来下载与远程模式匹配的多个文件.您还希望将 $ TIMESTAMP 作为模式的一部分.我建议是这样的:

You probably want to use the ftp client's mget command to download multiple files matching a pattern on the remote side. You also want to include $TIMESTAMP as part of the pattern. I'd suggest something like this:

ftp remote-hostname <<EOF
cd path/to/log/files
prompt
mget ${TIMESTAMP}0???vel.radar.h5
bye
EOF

这将使用此处文档(仅一行上的<< EOF EOF )将输入文本提供给ftp命令.它将扩展变量 $ TIMESTAMP ,使其成为 mget 命令的一部分,例如如果$ TIMESTAMP是12345,则将告诉ftp命令 mget 123450 ??? vel.radar.h5 .

This uses a here-document (<<EOF to EOF on a line by itself) to supply input text to the ftp commmand. It will expand the variable $TIMESTAMP so it becomes part of the mget command, e.g. if $TIMESTAMP was 12345, the ftp command will be told mget 123450???vel.radar.h5.

这篇关于bash脚本中的通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 11:50