我们的开发环境一般都使用windows操作系统,而测试环境和线上环境一般使用linux。windows下编辑的shell脚本,上传到windows下会发生错误。出现两种情况:
  1、BOM头问题,前面有介绍,不再继续
  2、回车符问题。 主要是在windows操作系统下,采用的编辑器(windows自带的文本编辑器或者zend studio)编辑shell脚本,在处理换行的时候,一般会附加一个回车符,在linux环境下运行,这个回车符会影响脚本运行,返回语法错误。

  我们看一下
  首先,我们在windows下编辑一个文本(test00.php),输入下面的内容,之后上传到linux服务器

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA5AAAACFCAIAAACi3YDGAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAMRUlEQVR4nO3dQWhb15oH8HMf3XuVEijzMsOzsnBUz9SlG6nD0Bko2JsGHthQAulisJcypYuK6bIPLWYIvkt35YEQasOAZ2ND4NWLqbVpk9cx9iYWzPCGwqPZyLt4dWchW7ESSddSZftE/v0Wjq9073e+69WfL0e6SbPZ3NzcvHv3buBy+bNfIX/8XP5EQ/OnuwQ///zzDz/88Dd/+/dX3ch19z///V+tXz744IN33nnnapthvCWtwHrVbQDAYP56+sOrboET/7v3/VW3wJh7q/XPrXfLV9sHAAwky7KrboETUgQX7TdX3QAAAPTz1tmDL36czL3gx8WRrX10dDQxMTGycgAAjJ3j4+OOCesfF45yfwIAwGXqCKz/tD7xx4Wj/j+vqlEAAK6nVyesuZn1qhoFAOB6MmEFACBqI56wHqxXq9VquvN8uG62l5Jy2hju2ouoE5vtpSRZ2r7qLgAALtUoJ6zPd9KH4V7t3t8N3c3sarZbefWbCtLywBmta52LNkSfg9YpTJVGsQIAwJtklBPWGx9Vagt3huujkZaTJEmSzsloIy0nyXL9m7nkRG4k7F4nhBDC6TtJUi6Xy2lOoe2lpH167rC2T5+Nl8smnYt26ecc91uaKuQ0AwAwXmLZwzpZ2c2y7HCl9PqrK6XFrezE6uxQdUJopOWN+cNWka1ivZ7f0d32ovMbhZyg3LvP9H572exwfqOdWbv3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AKImsAIAEDWBFQCAqAmsAABETWAFACBqAisAAFETWAEAiJrACgBA1ARWAACiJrACABA1gRUAgKgJrAAARE1gBQAgagIrAABRE1gBAIiawAoAQNQEVgAAoiawAgAQNYEVAICoCawAAERNYAUAIGoCKwAAURNYAQCImsAKAEDUBFYAAKImsAIAELX/B5gQq1yQQmfeAAAAAElFTkSuQmCC" alt="" />

  

  我们用vi打开看一下,似乎没有问题

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABIMAAABQCAIAAAAFjCIyAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAItElEQVR4nO3dMXLiaBoG4E9dc46JpHIRONpIPsFA9aYdOjQpBB068gFwasIOO50udANTE0zEVrm84gq7V/g3AGOMGQQsLdfYz1MdIfn/X3X2lj5JWUop+DD+Vf/3z/vf/3Hxz7cOAgAAH1o2+/d/3joDAADAx/LLn/e/v3UGAACAj+WXP/74460zAAAAfCzZi+fEqn7Wm43q+0H+/616qnUAAADeo09vHeBvpOpnWb966xQAAMDf38sm1r1LaeNG1lH1Y8s6P9upapK6BQAA/HSLJja/vciePNeQqp9lWW8cMe69Orbd9nU2j2QXt/OmXFX/+fSmbXfnXNt57edteZqut+iUTbEBAAD2sGhi+eA+pZTS5Gr9WPdu+dPVJC3cdXevtn2diKpfDM+fFtnrdlnxtV6eXI/K8c3O6rYj5/z2YrVzPZr1Vp1rW57DrxcAAOAY7TwnVnTKaKhTG/L8qazlZ+cxfaiP2nf+4/u0HH1d9Kn885dyudDheZbKTnFUEAAAgDXtNLF8cJ/St7jcb8YxItbHB3vjo/etH6YxHRbLhYrhNGaP8+PyAAAAnEyL705cji5Orsa9pgfF1ocKX406HqDolFGO6pQ2BxEPzLP6A+/lBwAATqCxiRWdcnkj6Xjzqnq5wPnZ7kJTP0xXg4Dzx9k+e2zNmX/+Uk6Hl5s9a1eeU1wvAADATo1NLB9cX60G/Pa7d/Ta483ThGCW9WajuulNGN27yWrTy7geleN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z4kBAAC0TRMDAABo2/8AuO4Wg0WyFf8AAAAASUVORK5CYII=" alt="" />

  我们再在linux服务器上直接写一个文件(test11.php)输入同样的内容。但是对比一下,我们可以清晰的看见两个文件的大小是不一样的

[root@localhost test]# ll test*
-rw-rw-r-- root root Mar : test00.php
-rw-r--r-- root root Mar : test11.php

使用xxd去看一下编码情况,做一下对比:

windows下 linux下
:       210d 0a69  it is a test!..i
: 0d0a t is a test!..it
: 210d 0a69 is a test!..it
: is a test!
:       210a   it is a test!.it
: 210a is a test!.it i
: 210a s a test!.it is
: 210a a test!.

我们清晰的看到,windows下编辑的文件上传到linux服务器后,每一次换行符前面(0a)都存在回车符(0d)。

那么怎么解决这个问题呢
方法很多,可以使用dos2unix filename命令解决即可

[root@localhost test]# dos2unix test00.php
dos2unix: converting file test00.php to UNIX format ...
[root@localhost test]# xxd test00.php
: 210a it is a test!.it
: 210a is a test!.it i
: 210a s a test!.it is
: a test!
[root@localhost test]#

windows编辑文本和unix编辑文本的回车符问题的更多相关文章

  1. 去除windows编辑文本中的回车符

    情景描述: 最近,huskiesir的朋友遇到了一个很奇葩的问题.那就是他在windows上搭建了一个http服务,把A脚本放在了上面并用linux去下载和执行,但是在执行的时候出现了问题,在linu ...

  2. HTML:<input type="text">文本框不可编辑的方式

    1.<input type="text" name="name" value="姓名" disabled /> 该方式显示的文本 ...

  3. Swing文本域的编辑

    1..setEditable(false); 设置文本域不可编辑 2..setHorizontalAlignment(JTextField.CENTER); // 设置文本的水平对齐方式 有效值包括: ...

  4. 限制可编辑div只能输入纯文本

    本博客转载自张鑫旭大神的一篇文章:小tip: 如何让contenteditable元素只能输入纯文本,原文地址:http://www.zhangxinxu.com/wordpress/2016/01/ ...

  5. sed - 文本三剑客之编辑功能

    sed - stream editor for filtering and transforming text Sed是一个流编辑器.流编辑器用于对输入流(文件或管道输入)执行基本的文本转换.虽然在某 ...

  6. Unity3D 之UGUI 文本框和编辑框

    这里来讲解一下unity3D自带的UI功能,自带的UI也叫UGUI功能非常的强大,比起NGUI,更加的灵活,让用户能够更加容易的去使用. 首先创建一个文本Text 然后是文本相对应的属性 这里的属性比 ...

  7. 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox

    [源码下载] 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox 作者:webabcd ...

  8. 【Windows 10 应用开发】细说文本资源文件(resw)

    最近,小戏骨版<红楼梦>很是火热,老周一口气看完了9集,一直看到 Surface 的风扇呼呼响.林黛玉和薛宝钗这两个角色都演得不怎么样,倒是演史湘云的娃娃演得不错,老周甚是喜欢. 于是,昨 ...

  9. linux tr命令实现windows文本格式与linux文本格式间的转换

    tr 命令 转换和删除字符 选项: -d --delete:删除字符 -s --squeeze-repeats:把连续重复的字符以一个字符表示,即去重 -c –C --complement:取字符集的 ...

随机推荐

  1. linux crontab 计划任务 atd和windows下的计划任务

    crontab 命令 如果发现您的系统里没有这个命令,请安装下面两个软件包. vixie-cron crontabs crontab 是用来让使用者在固定时间或固定间隔执行程序之用,换句话说,也就是类 ...

  2. List<T> 和DataTable的相互转换

    我用的将集合类转换为DataTable 的方法 /// <summary> /// 将集合类转换成DataTable /// </summary> /// <param ...

  3. GruntJs安装及使用入门(自定义grunt任务,合并压缩js、css)

    一.Grunt.js简介(实现自动化) 1)简要说明: 1.GruntJs是基于node的javascript命令行工具,可以自动化构建.测试.生成文档的项目管理工具: 2.使用GruntJs可以自动 ...

  4. Objective-C中变量采用@property的各个属性值的含义

    我们在OC中定义变量,可以自己来定义变量的setter方法来设置变量值,用getter方法来获取变量值.但是当变量数量增多时,还采用手动添加setter/getter方法来操作变量,就会使得程序代码量 ...

  5. config large memory

    C Configuring Large Memory Optimization This appendix provides information for configuring memory op ...

  6. Android应用开发学习之图片切换器

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 如果我们要实现类似Windows的照片查看器切换上一张下一张照片的效果,可以使用图片切换器ImageSwitcher ...

  7. jquery and js 判断一个元素是否存在

    一.javascript中判断一个元素是否存在 if(document.getElementById('example')){ // do sth } 二.jquery中判断一个元素是否存在 < ...

  8. SQL语句查询结果额外加入一列序号自己主动添加

    sqlserver 能够用row_number函数实现 例如以下: SELECT *,row_number() OVER(ORDER BY score(列名) DESC) AS rank FROM s ...

  9. shape 填充 圆角矩形 圆形 环形

    属性 使用中可能出现的问题: 如果在某些手机中使用 shape 出现黑色填充背景,设置<solid android:color="@color/transparent"/&g ...

  10. java07循环结构

    public class WhileTest { // while循环结构 public static void main(String[] args) { System.out.println(&q ...