在 bash 脚本中使用通配符
我正在创建一个 bash 脚本,它将使用 SQL*Loader 加载 CSV 文件。请参考下面的代码:
#!/bin/bash
FILENAME = '/u02/logs/$(date -d '2 days ago' +%Y-%m-%d)*.csv'
# LOAD CSV FILE USING SQL*LOADER
sqlldr username/password@localhost control=control.ctl data=$FILENAME
但是,当我尝试运行此脚本时,收到以下错误: SQL*Loader-500: 无法打开文件 (/u02/logs/*
2011-11 -06*
.csv)。我发现问题是我的 * 通配符在 bash 中被解释为字符串而不是通配符。
有没有办法告诉 bash 我的星号 (*) 是通配符而不是字符串?
感谢您的支持。
I'm creating a bash script that will load CSV files using SQL*Loader. Please refer to the code below:
#!/bin/bash
FILENAME = '/u02/logs/$(date -d '2 days ago' +%Y-%m-%d)*.csv'
# LOAD CSV FILE USING SQL*LOADER
sqlldr username/password@localhost control=control.ctl data=$FILENAME
However, when I try to run this script, I recieved the following error: SQL*Loader-500: Unable to open file (/u02/logs/*
2011-11-06*
.csv). I figure out that the problem is my * wildcard which is being interpreted as a string instead of a wildcard in bash.
Is there a way to tell the bash that my asterisk (*) is a wildcard and not a string?
Thank you for your support.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道 sqlldr,但我认为你可以尝试:
希望它有帮助
i dont know about sqlldr, but i think you can try:
hope it helps
您使用单刻度是问题所在。另外,我不习惯看到 bash 代码在等号周围有空格。话又说回来,我已经老了。所以这就是我要做的:
应该可以了。您不需要在第一部分周围加上引号,因为它们是字面意思。仅当您需要解释器进行一些插值时才使用双引号。当您不希望解释器触及它时,请使用单引号。
Your use of single ticks is the problem. Also, I'm not used to seeing bash code have spaces surrounding the equals sign. Then again, I'm old skool. So this is what I'd do:
That should do it. You don't need quotes around the first part since they're literal. Only use double quotes when you need the interpreter to do do some interpolation. Use single quotes when you don't want the interpreter to touch it.
只需使用
我还注意到错误消息中的
logs/
之后的附加*
,但不在代码中。相应地进行调整。如果没有与通配符模式匹配的文件,则
*
将保留在文件名中。另外,请注意存在多个匹配文件的情况。Just use
I also note additional
*
after thelogs/
in your error message, but not in your code. Adjust accordingly.The
*
will stay in the filename if there is no file matching the wildcard pattern. Also, be careful where more than one matching file exists.也许你可以尝试:
Maybe you can try: