简体   繁体   English

文件名的一部分时,Shell脚本不执行星号

[英]Shell Script Not Executing Asterisk When Part Of Filename

So the use case is pretty simple, if I run the command in the terminal like this 因此,用例非常简单,如果我在这样的终端中运行命令

myCommand -input file_prefix* -output outputFolder

It will grab all of my files that have that prefix that are inside the directory, run the command and spit it into the output folder. 它将抓取我目录中所有带有该前缀的文件,运行命令并将其吐到输出文件夹中。 Pretty easy on its own. 本身很容易。 However if I copy paste that exact command into a Shell Script to be run when in PHP or similar it says file_prefix* no file found. 但是,如果我将确切的命令复制粘贴到要在PHP或类似版本中运行的Shell脚本中,则会显示file_prefix *找不到文件。 This is because it is reading the asterisk as a literal character and not the wildcard. 这是因为它将星号读取为原义字符而不是通配符。 I have tried wrapping the asterisk in single quotes, double quotes etc. Any idea on how this can be done? 我曾尝试将星号用单引号,双引号等引起来。关于如何做到这一点的任何想法? I have seen a few examples of people echoing the asterix, but no one using it in the way I am as part of a file prefix. 我已经看到了一些人们在使用星号的示例,但是没有人以我作为文件前缀的一部分的方式使用它。 Thanks for any help! 谢谢你的帮助!

It looks like the proper answer to this was actually to put my file_prefix into quotes and to leave the asterisk alone. 看来,正确的答案实际上是将我的file_prefix放在引号中,而不要使用星号。 Final working copy 最终工作副本

myCommand -input 'file_prefix'* -output outputFolder

my file_prefix was an input param so the actual final code is 我的file_prefix是输入参数,所以实际的最终代码是

myCommand -input '$1'* -output $2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM