user3806680
user3806680

Reputation: 21

Regex not substituting file name

I am trying to run this command from a script and it seems that it fails to match the value of regex.

cat /config.yml_orig >> /build/Product*/config.yml

And it fails with

/build/Product*/config.yml: No such file or directory

The product number of the directory keeps on changing so I have substituted with * but on command line it fails to match the regex for this.

What is the solution for this when the commands fails to identify its a regex.

Upvotes: 1

Views: 34

Answers (2)

user108471
user108471

Reputation: 2607

The pattern is trying to match the whole thing, and it's failing if the "config.yml" file doesn't exist. Try:

cat config.yml_orig >> "$(echo /build/Product*)"/config.yml

Upvotes: 0

Barmar
Barmar

Reputation: 780889

A wildcard will only match an existing file, so you can't use it if you're creating the file. You need to get the directory separately with a wildcard, then append the filename:

dir=$(echo /build/Product*)
cat config.yml_orig >> "$dir"/config.yml

Upvotes: 1

Related Questions