文件名在变量中包含空格和通配符 [英] filename contains space and wildcard in a variable

查看:105
本文介绍了文件名在变量中包含空格和通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到名称包含空格并每周更改的文件(名称包含星期数)

I receive files which names contain spaces and change every week (the name contains the week number)

IE,本周的文件看起来像This is the file - w37.csv

IE, the file for this week looks like This is the file - w37.csv

我必须编写脚本以将此文件考虑在内. 我没有成功编写此脚本.

I have to write a script to take this file into account. I didn't succeed in writing this script.

如果我这样做:

    $FILE="This is the file - w*.csv"

我找不到/dir/${FILE}

我尝试了"This\ is\ the\ file - w*.csv"

我尝试了/dir/"${FILE}""/dir/${FILE}"

但是我仍然找不到我的文件

But I still can't find my file

看起来变量名称中的空格需要用双引号引起来,但是通配符没有被分析.

It looks like the space in the name needs the variable to be double-quoted but, then, the wildcard is not analysed.

您有个主意(或答案)吗?

Do you have an idea (or THE answer)?

此致

奥利维尔

推荐答案

echo /dir/"This is the file - w"*.csv

或-您几乎尝试过该操作-

or — you almost tried that —

echo /dir/This\ is\ the\ file\ -\ w*.csv

这篇关于文件名在变量中包含空格和通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆