BASH:if语句执行命令和函数
我遇到了一个我认为应该很容易解决的问题,但对于我的一生,我无法解决。可能是真的很晚了;没有把握。
所以我有一个 shell 脚本和一个需要运行的 if 语句。问题是我在这个 bash 脚本中有一个函数,我用它来在 if 语句中实际构建这个 find 命令的一部分。我想知道如何在不收到错误[:太多参数
的情况下同时执行这两项操作。
这是当前的代码:
if [ -n `find ./ `build_ext_names`` ];then
这就是我真正需要发布的内容。我需要弄清楚如何在 find 命令中运行 build_ext_names
,而该命令又位于 ifstatement 中
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Michael Aaron Safyan 的想法是正确的,但解决眼前的问题,您可以使用更简单的
$(command)
构造来代替 命令替换。它允许更简单的嵌套: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:如果你把它分开的话会更容易:
This is easier if you split it up: