0

For example, I want to run find but the parameter is stored in a varibile.

a='-name "build.sh"'
find . $a

It shows error: find: -name "build.sh": unknown primary or operator

I hope it runs like find . -name "build.sh", how to put the var as parameter`?

Thank you.

2
  • 1
    Use shell array: a=("-name" "build.sh"); find . "${a[@]}" Commented Apr 1, 2022 at 11:55
  • Written like this, your command would try to find a file which name is "build.sh", including quotes. It's not the expected behaviour, but it should not give you any error. Are you sure you didn't add a special character in your command, like a non-breakable space? Commented Apr 1, 2022 at 12:15

1 Answer 1

1

Throw your code into a file and then use shellcheck on it, and it will lead you to this page:

https://github.com/koalaman/shellcheck/wiki/SC2089

Quotes/backslashes will be treated literally. Use an array.

Do it this way, instead:

a=(-name "build.sh")
find . "${a[@]}"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.