摘要: 在匹配字符串时用了类似这样的语句if[$timeofday="yes"];thenecho"Goodmorning"exit0报错的原因是:如果变量timeofday的值为空,那么就if语句就变成了if[="yes"],这不是一个合法的条件。为了避免出现这种情况,我们必须给变量加上引号if["$timeofdat"="yes"],这样即使是空变量也提供了合法的测试条件,,if[""="yes"] 阅读全文
posted @ 2013-07-19 12:07 gxcherie 阅读(45517) 评论(0) 推荐(3) 编辑
摘要: 有时候shell在运行的时候可能会报toomanyarguments错误,出现这种错误的一般情况是出现了多值问题,也就是一个变量可能有多个值了。例:#!/bin/shecho"Isitmorning?Pleaseansweryesorno"readtimeofdayif[$timeofday="yes"];thenecho"Goodmorning"elif[$timeofday="no"];thenecho"Goodafternoon"elseecho"Sorry,$timeofday 阅读全文
posted @ 2013-07-19 12:06 gxcherie 阅读(4764) 评论(0) 推荐(0) 编辑
摘要: cygwin下面写shell,运行出错:syntax error near unexpected token `$’do\r”MicrosoftInternetExplorer402DocumentNotSpecified7.8Web0写shell,运行出错:syntaxerrornearunexpectedtoken`$’do\r”【问题】在cygwin下,用notepad++写了个简单的shell脚本,内容如下:12345678910111213#!/bin/bash#remove*.bakinsubfolderfilesecho'remove*.bak'sub_folde 阅读全文
posted @ 2013-07-19 12:04 gxcherie 阅读(36628) 评论(1) 推荐(1) 编辑
摘要: 出现badinterpreter:Nosuchfileordirectory的原因是文件格式的问题。这个文件是在Windows下编写的。换行的方式与Unix不一样,但是在VI下面如果不Set一下又完全看不出来。解决方法:1、上传到linux主机运行chmod+xback./back错误提示如下:bash:./back:badinterpreter:Nosuchfileordirectory2、错误分析:因为操作系统是windows,在windows下编辑的脚本,所以有可能有不可见字符。从你的脚本及报告的错误看来,很有可能是你的脚本文件是DOS格式的,即每一行的行尾以\r\n来标识,其ASCII 阅读全文
posted @ 2013-07-19 12:01 gxcherie 阅读(733) 评论(0) 推荐(0) 编辑
摘要: 1.文件管理Øtouch新建文件。例:touchtest.txt新建一个test.txt文件。Øcp复制文件。例:cp./user_one/test_one./user_two/test_two,将user_one目录下的test_one文件复制到user_two目录下面,并且命名为test_two。加参数-i会在有重名是询问是否要覆盖。Ømv文件或目录改名,或者用于将一个文件由一个目录移动到另外一个目录。例:mv./user_one/test_one./user_two,将user_one下面的test_one文件移动到user_two下面。Ørm文件 阅读全文
posted @ 2013-07-19 11:59 gxcherie 阅读(389) 评论(0) 推荐(0) 编辑