免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1308 | 回复: 1
打印 上一主题 下一主题

A simple shell script to execute a command package [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-08-09 12:30 |只看该作者 |倒序浏览
Hi folks,

I'm prepared to write a simple script to execute 20+ commands and could not figure out how to make use of "loop" subject to certain conditions.

If without conditions
  1. #!/bin/bash

  2. cmd1="code1" #the exact/full command
  3. cmd2="code2" #the exact/full command
  4. cmd3="code3" #the exact/full command
  5. etc.

  6.      cmd1 || exit 1
  7.      cmd2 || exit 2
  8.      cmd3 || exit 3
  9.      ...
  10.      cmdn || exit n
  11.      echo "Build environment entered!"
  12. exit 0
复制代码


It will be a long script.  Please advise how to apply "loop" to shorter the script executing all command subject to following conditions

1) All commands except cmd3 should have no output.  If there is any it needs to confirm either to continue OR to exit the shell

2) cmd3 should have "/mnt/abc_dir" output.  If no output OR empty output the shell should exit, not continue executing further commands

TIA

satimis

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
2 [报告]
发表于 2005-08-09 12:49 |只看该作者

A simple shell script to execute a command package

for((i=1;i<=n;i++))
do
eval \$cmd$i
done
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP