初学shell脚本编程注意空格问题

来源:互联网 发布:cf按键精灵自瞄源码 编辑:程序博客网 时间:2024/05/29 13:16

一、什么是shell编程

       shell编程就是利用shell的功能所写的一个程序,这个程序是使用纯文本文件,将一些shell的指令写在里面,然后用正规表示法,管道命令以及数据流重导向等功能,以达到我们所想要的处理目的。我们使用到shell有bash,sh,csh,ksh常用的是bash。

二、shell编程要注意到空格问题

      我们举个例子来说吧
     
#!/bin/bashfunction show_usag {    #show_usag 应该与"{" 分开    echo "Usage $0 source_dir dest_dir"    exit 1}#Main program starts hereif [ $# -ne 2 ]; then            show_usag;else #There are two arguments    if [ -d $1 ] ;then        source_dir=$1      # source_dir 是变量, 复制表达式 等号两边不能有空格    else        echo "lnvalid source directory"        show_usag    fi    if [ -d $2 ]  ; then        dest_dir=$2    else       echo "lnvaild destination directory"    fifiprintf " Sorce directory is ${source_dir}\n"  #这里也是到 printf 不能“ 连在一起printf " Destination directory is ${dest_dir}\n"


0 0
原创粉丝点击