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\n"
~
使用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$
Ubuntu下sh *.sh使用==操作符执行报错的更多相关文章
- ubuntu系统普通用户sudo命令执行报错解决方案
通过adduser user1命令创建普通用户,且使该用户具有sudo权限(将该新用户user1添加到sudo或root用户组中,或者修改/etc/sudoer文件),但是依然无法执行sudo指令,会 ...
- windows中修改catalina.sh上传到linux执行报错This file is needed to run this program解决
windows中修改catalina.sh上传到linux执行报错This file is needed to run this program解决 一.发现问题 由于tomcat内存溢出,在wind ...
- 在Ubuntu下安装*.sh
在Ubuntu下安装*.sh和*.bin的方法 [日期:2009-12-07] 来源:Linux公社 作者:Linux编辑 [字体:大 中 小] 记下在Ubuntu下安装*.sh和*.bin的简 ...
- oracle创建包后执行报错:object omgmig.test_package is invalid.
今天学习了一下oracle的包的写法,然后碰到这么个问题.包声明和包主体都正确,但是就是执行报错:object omgmig.test_package is invalid. 这是会报错的sql,看起 ...
- idea lib下有jar包但是仍然报错 找不到类
现象: idea lib下有jar包但是仍然报错 找不到类 但是有个奇怪现象 同样的配置下项目在eclipse中可以正常编译 启动. package com.puhui.car.aspect; imp ...
- ubuntu上跑python连接pg,报错 ImportError: No module named psycopg2
ubuntu上跑python连接pg,报错 ImportError: No module named psycopg2 root@pgproxy1:~# python /home/zxw/PGWri ...
- 解决Windows下运行php Composer出现SSL报错的问题
解决Windows下运行php Composer出现SSL报错的问题 2015-01-14 20:05 在windows下运行composer却出现SSL报错: E:\www>php -f ...
- salt执行报错一例
执行报错: 查看服务端日志: 认证有问题 重新认证吧!!! minion端: [root@super66 ~]# cd /etc/salt/[root@super66 salt]# lsminion ...
- 解决Win7下运行php Composer出现SSL报错的问题
以前都在linux环境使用php composer.今天尝试在win7下运行composer却出现SSL报错: D:\data\www\mmoyu\symapp>php -f %phprc%\c ...
随机推荐
- 【Thinking in Java, 4e】初始化与清理
[用构造器确保初始化] [方法重载] 涉及基本类型的重载 1.如果传入的数据类型小于方法中声明的形式参数类型:实际数据类型会被提升. 2.如果传入的数据类型大于方法中声明的形式参数类型:编译器报错,应 ...
- 深入 CommonJs 与 ES6 Module
目前主流的模块规范 UMD CommonJs es6 module umd 模块(通用模块) (function (global, factory) { typeof exports === 'obj ...
- 20145328 《Java程序设计》第6周学习总结
20145328 <Java程序设计>第6周学习总结 教材学习内容总结 输入/输出 InputStream与OutputStream 从应用程序角度来看,如果要将数据从来源取出,可以使用输 ...
- ubuntu18.04安装ssh服务
1.安装openssh-server sudo apt-get install openssh-server 2.启动ssh服务 sudo service ssh start 3.检测是否启动了ssh ...
- CentOS 7 Fail2ban防暴力破解
1.安装 yum install epel-release -y yum install fail2ban fail2ban-systemd -y 2.配置 //新建配置 vim /etc/fail2 ...
- [Pytorch]PyTorch Dataloader自定义数据读取
整理一下看到的自定义数据读取的方法,较好的有一下三篇文章, 其实自定义的方法就是把现有数据集的train和test分别用 含有图像路径与label的list返回就好了,所以需要根据数据集随机应变. 所 ...
- hdu1009 - 贪心
2017-07-14 18:18:31 writer:pprp 介绍:hdu1009 题目介绍,详见hdu1009 代码如下 #include <iostream> #include &l ...
- C#代码实现 Excel表格与Object互相转换,Excel表格导入数据库(.NET2.0 .NET4.0)
前些天在工作上遇到这个需求,在GitHub找到一个开源代码可以用,Fork了一个版本,整理一下发出来. ①.Net项目中使用Nuget安装一个 NPOI 包 https://github.com ...
- ThinkPHP开发笔记-用户登录注册
1.修改模块配置,Application/当前模块名/Conf/config.php <?php return array( //数据库配置信息 'DB_TYPE' => 'mysql', ...
- 公众号菜单中的click
$params = [ 'button' => [ [ 'type'=>'click', 'name'=>'就送帽子', 'key'=>'V1001_PRESENT', ], ...