CMOS
CMOS

Reputation: 2917

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. 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!

Upvotes: 0

Views: 1657

Answers (1)

CMOS
CMOS

Reputation: 2917

It looks like the proper answer to this was actually to put my file_prefix into quotes and to leave the asterisk alone. Final working copy

myCommand -input 'file_prefix'* -output outputFolder

my file_prefix was an input param so the actual final code is

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

Upvotes: 1

Related Questions