csh与bash比较:
一、csh的while循环控制结构及if then:
#!/bin/csh -f
while ($#argv >= 1)
  if ("$1" == "-s") then
    shift
    if ($#argv >= 1) then
      set source = $1
      shift
    endif
  else if ("$1" == "-c") then
    set complex = "-text"
    shift
  else
    if ($?text == "0") then
      set text = $1
    endif
    shift
  endif
end

而bash的for结构的if then :
#!/bin/sh
for file in *
do
   if grep -q POSIX $file
   then
      echo $file
   fi
done
exit 0
即c语言风格的csh,如if endif, while end结对,而linux下的bash形式为 if  fi,  for do done.

比较二:
csh的判断文件存在:
if (-e $MGDATA/${text}.chunks) then
  set input_files = `cat $MGDATA/${text}.chunks`
endif

而bash则是:
if test -f fred.c
then
...
fi
或者使用
if [ -f fred.c ]
then
...
fi
即方括号[]相当test命令的效果,注意:如果需要把then放在if的同一行,需要在方括号[]后加一个分号;
if [ -f fred.c ]; then
...
fi

root@host% tnpdump 
   Name                TNPaddr   MAC address    IF     MTU E H R
cluster1.node0     0x1100001 02:00:00:01:00:04 em0    1500 2 0 3
node0.fpc3         0x1100013 02:00:00:01:00:13 em0    1500 5 0 3
node0.fpc5         0x1100015 02:00:00:01:00:15 em0    1500 4 0 3
node0.fpc11        0x110001b 02:00:00:01:00:1b em0    1500 5 0 3
node0.fpc3.pic0    0x1100113 02:00:00:01:01:13 em0    1500 2 0 3
node0.fpc5.pic0    0x1100115 02:00:00:01:01:15 em0    1500 2 0 3
node0.fpc3.pic1    0x1100213 02:00:00:01:02:13 em0    1500 3 0 3
node0.fpc5.pic1    0x1100215 02:00:00:01:02:15 em0    1500 3 0 3
cluster1.node1     0x2100001 02:00:00:02:00:04 em0    1500 0 0 3
cluster1.node1     0x2100001 02:00:01:02:00:04 em1    1500 0 1 3
node1.re0          0x2100004 02:00:00:02:00:04 em0    1500 0 0 3
node1.re0          0x2100004 02:00:01:02:00:04 em1    1500 0 1 3
node1.fpc3         0x2100013 02:00:00:02:00:13 em0    1500 4 0 3
node1.fpc5         0x2100015 02:00:00:02:00:15 em0    1500 4 0 3
node1.fpc11        0x210001b 02:00:00:02:00:1b em0    1500 5 0 3
node1.fpc3.pic0    0x2100113 02:00:10:02:01:13 em0    1500 3 0 3
node1.fpc5.pic0    0x2100115 02:00:00:02:01:15 em0    1500 3 0 3
node1.fpc3.pic1    0x2100213 02:00:10:02:02:13 em0    1500 2 0 3
node1.fpc5.pic1    0x2100215 02:00:00:02:02:15 em0    1500 3 0 3
node1.fpc3.pic2    0x2100313 02:00:10:02:03:13 em0    1500 3 0 3
node1.fpc3.pic3    0x2100413 02:00:10:02:04:13 em0    1500 2 0 3
cluster1.master    0xf100001 02:00:00:02:00:04 em0    1500 0 0 3
cluster1.master    0xf100001 02:00:01:02:00:04 em1    1500 0 1 3
bcast             0xffffffff ff:ff:ff:ff:ff:ff em0    1500 0 0 3
bcast             0xffffffff ff:ff:ff:ff:ff:ff em1    1500 0 1 3

root@host% cat p.sh 
#!/bin/csh

foreach pic (`tnpdump | awk '{print $1}' | grep pic`) 
        echo $pic 
end

root@host% ./p.sh 
node0.fpc3.pic0
node0.fpc5.pic0
node0.fpc3.pic1
node0.fpc5.pic1
node1.fpc3.pic0
node1.fpc5.pic0
node1.fpc3.pic1
node1.fpc5.pic1
node1.fpc3.pic2
node1.fpc3.pic3

csh与bash比较的更多相关文章

  1. FreeBSD更换默认csh为bash

    1.安装bash cd /usr/ports/shells/bash make install 2.切换chsh(change shell) chsh -s /usr/local/bin/bash

  2. 跟着鸟哥学Linux系列笔记3-第11章BASH学习

    跟着鸟哥学Linux系列笔记0-扫盲之概念 跟着鸟哥学Linux系列笔记0-如何解决问题 跟着鸟哥学Linux系列笔记1 跟着鸟哥学Linux系列笔记2-第10章VIM学习 认识与学习bash 1. ...

  3. bash及其特性(笔记)

    bash及其特性:shell: 外壳GUI:Gnome, KDE, XfceCLI: sh, csh, ksh, bash, tcsh, zsh root, student程序:进程 进程:在每个进程 ...

  4. linux的学习之路--(五)bash及其特性

    操作系统组成作用shell是离用户最近的程序 shell:外壳 两类 GUI:Gnome,KDE,Xfce CLI:sh, csh,ksh,bash(都是程序,就是功能支持的不同而已) 进程:在每个进 ...

  5. 《鸟哥的Linux私房菜》学习笔记(2)——Bash特性

    一.shell的基本概念:                               shell 意思是外壳,它是离用户最近的程序.shell提供用户操作系统的接口,我们通过shell将输入的命令与 ...

  6. linux初级学习笔记五:bash特性详解!(视频序号:03_2,3)

    本节学习的命令:history,alias,ualias,\CMD 本节学习的技能:   bash的特性 光标跳转 查看命令历史 命令历史的使用技巧 给命令起别名 命令替换 文件名通配符 shell: ...

  7. linux bash变量作用域

    linux bash变量作用域 一,思考一个问题,当在shell里执行某个程序时,shell是怎么找到这个程序的? shell会去$PATH环境变量定义的目录里去找这个命令.环境变量里一般包括/usr ...

  8. linux中的bash

    一.bash的简介 操作系统都是需要通过shell跟内核来交互的,常见的shell有GUI.KDE.sh.csh.bash.tsh.zsh等. 而linux中最常用的shell就是bash. 二.ba ...

  9. FreeBSD csh shell 配置

    在/etc/csh.cshrc里面加入: alias ls ls –G, 并重新登录 问:如何让FreeBSD的csh像bash那样按tab列出列出无法补齐的候选文件? 答:标准的方法是按Ctrl+D ...

随机推荐

  1. C# 反射学习总结

    C#中的反射可以使得程序集和类型(类.结构.委托.接口和枚举)以及类型中的成员(方法.字段.属性.事件.参数.构造函数等)都成为变量在编程中动态调用.

  2. c语言调试接口

    http://blog.chinaunix.net/uid-10106787-id-2985587.html 在C语言程序设计中,常会出现各种各样的bug:段错误.参数异常等等.我们需要尽快定位错误, ...

  3. css 动画效果

    要搞就搞明白,一知半解时停止研究 损失最大     css3意义: CSS3 动画 通过 CSS3,我们能够创建动画,这可以在许多网页中取代动画图片.Flash 动画以及 JavaScript. 重点 ...

  4. oracle 自定义函数

    函数和存储过程类似,可以简单的理解为一段可以执行某个活动/动作的子程序,可以作为一个系统对象被存储在数据库中,可以重复调用.与存储过程不同的是,函数总是向调用者返回一个值,而存储过程不能有返回值. C ...

  5. python学习小结2:if和while控制语句

    if语句 if语句中,代码块是按缩进的空格数量来判断的,也就是说空格数量一致的相邻行会被当作一个代码块,当if的条件成立的时候它就会得到执行. x = 100 if x > 50: print ...

  6. AvalonDock 2.0+Caliburn.Micro+MahApps.Metro实现Metro风格插件式系统(菜单篇)

    这章主要说插件的菜单,可以说菜单是最核心的部分,前面我们已经实现了Document添加,现在主要就是生成具有层级关系的菜单,以及把菜单跟我们自定义的Document关联起来,也就是MenuPart-& ...

  7. 【转】Dancing Links题集

    转自:http://blog.csdn.net/shahdza/article/details/7986037 POJ3740 Easy Finding [精确覆盖基础题]HUST1017 Exact ...

  8. reset内容

      /*reset */div,p,a,span,body,dl,dt,dd,header,footer,img,section,time,h2,em,article,h3,h4,ul,li,labe ...

  9. unity3d android互调

    unityPlayer = new AndroidJavaClass("com.xxx.xxx.MainActivity"); curActivity = unityPlayer. ...

  10. 利用Qemu Guest Agent (Qemu-ga) 实现 Openstack 监控平台

    经常使用vmWare的同学都知道有vmware-tools这个工具,这个安装在vm内部的工具,可以实现宿主机与虚拟机的通讯,大大增强了虚拟机的性能与功能, 如vmware现在的Unity mode下可 ...