我必须编写一个脚本来查找特定目录中的所有文件夹,然后为每个文件夹运行一个命令。
例如:有5个文件夹列为
它应该按照命令运行
答案 0 :(得分:0)
这对于一些shell扩展来说相当容易......你甚至不需要使用正则表达式或者找到xargs来解决这个问题...... 我会用*通配符来做,但这里的问题是你想如何处理命令的输出...
仅针对手头具体问题的答案:
splunkforwarder_TEST_MLC_*/bin/splunk start &
"&"只是将进程发送到后台并允许shell执行剩余的命令。
答案 1 :(得分:0)
使用循环:
#!/bin/bash
for dir in splunkforwarder_TEST_MLC_app*/; do
[[ -x "$dir"bin/splunk ]] || continue # skip if there is no splunk here
"$dir"bin/splunk start
done
/
扩展为目录splunkforwarder_TEST_MLC_app04/
,splunkforwarder_TEST_MLC_app05/
等。