BASH: if statement execute command and function
I've run into an issue in which I think should be easy to resolve, but for the life of me, I can't figure it out. Could be that 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 am using to actually build part of this find command inside the if statement. I开发者_运维知识库 want to know how I can do both, without receiving an error [: too many arguments
.
Here's the current code:
if [ -n `find ./ `build_ext_names`` ];then
That's all I really need to post. I need to figure out how to run that build_ext_names
inside that find command, which in-turn is inside the ifstatement
Michael Aaron Safyan has the right idea, but to fix the immediate problem you can just use the simpler $(command)
construct instead of ```command` `` for command substitution. It allows for much simpler nesting:
if [ -n "$(find ./ "$(build_ext_names)")" ]; then
This is easier if you split it up:
function whateverItIsYouAreTryingToDo() {
local ext_names=$(build_ext_names)
local find_result=$(find ./ $ext_names)
if [ -n "$find_result" ] ; then
# Contents of if...
fi
}
精彩评论