zoukankan      html  css  js  c++  java
  • Ubuntu下sh *.sh使用==操作符执行报错

    ————《鸟哥的Linux私房菜——基础篇》学习笔记

    ubuntu默认的sh是连接到dash,而我们写shell脚本时使用的时bash。bash和dash在一些方面是不兼容的。因此执行同一个脚本,两者结果不一样,可能用./*sh可以执行,而sh *.sh报错。

    为了正确实行使用./*.h 或者  bash *.sh  或者把==换成=(不兼容部分)

    也可以直接让系统不使用dash。。。。Ubuntu之所以使用dash是因为其体积小,兼容性高,但是悲催的时,一些bash可执行的脚步在dash下不能执行了。

    鸟哥私房菜13章学习shell script 中2.2节有一个例子sh06.sh

    #!/bin/bash
    #Program
    # "test the func of []"
    #History:
    #2014-08-14     Windeal
    #version        1
    #All rights reserved;
    
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
    export PATH
    read -p "Please enter (y/n):" yn
    [ "$yn" == "Y" -o "$yn" == "y" ] && echo "your input is y" && exit 0
    [ "$yn" == "N" -o "$yn" == "n" ] && echo "your input is n" && exit 0
    echo "I don't know what you choice
    "
    ~     
    
    使用sh执行报错:

    windeal@ubuntu:~/Windeal/shell$ sh sh06.sh 
    Please enter (y/n):y
    sh06.sh: 12: [: y: unexpected operator
    sh06.sh: 13: [: y: unexpected operator
    I don't know what you choice
    
    windeal@ubuntu:~/Windeal/shell$ 
    

    使用./sh06.sh 可以执行

    windeal@ubuntu:~/Windeal/shell$ ./sh06.sh 
    Please enter (y/n):y
    your input is y
    windeal@ubuntu:~/Windeal/shell$ 
    



  • 相关阅读:
    python之shutil模块
    python的os模块
    python的map函数
    Web基础知识
    Web基础知识 --- html中的meta元素有什么用?
    使用技巧 --- 与 FireFox 相关
    基础知识之WIN32 API
    资料索引
    基础知识之C++篇
    使用技巧 --- 与 Visual Studio 有关
  • 原文地址:https://www.cnblogs.com/Windeal/p/4284670.html
Copyright © 2011-2022 走看看