BASH: if statement executes command and function

I ran into a problem in which, I think, it is easy to solve, but for my life I can’t understand. Maybe it's really late; not sure.

So, I have a shell script, and I have an if statement that I need to run. The problem is that I have a function inside this bash script that I use to actually create part of this find command inside the if statement. I want to know how I can do both without getting the error [: too many arguments .

Here's the current code:

  if [-n `find ./` build_ext_names``]; then

That is all I really need to post. I need to figure out how to run this build_ext_names inside this find command, which in turn is inside the ifstatement

+4
source share
2 answers

Michael Aaron Safyan has the right idea, but to fix the immediate problem you can simply use the simpler $(command) construct instead of the `` command`` to replace the commands . This allows you to greatly simplify the investment:

 if [ -n "$(find ./ "$(build_ext_names)")" ]; then 
+12
source

This is easier if you split it:

 function whateverItIsYouAreTryingToDo() { local ext_names=$(build_ext_names) local find_result=$(find ./ $ext_names) if [ -n "$find_result" ] ; then # Contents of if... fi } 
+2
source

All Articles