zoukankan      html  css  js  c++  java
  • linux执行sh,出现/bin/sh^M: bad interpreter: No such file or directory

    一般情况是出现了出现这种情况,通过vim命令查看系统编码格式,

    #vim filename

    :set fileformat(或者:set ff)

    可以看到 fileformat=dos

    分析是系统编码格式造成的异常,解决方案:

    1、直接这vim中执行

    :set fileformat = unix或者:set ff = unix

    :wq

    保存后的文件就强制转为unix系统编码格式;

    有时候需要多个文件转化系统编码格式,那么用第二个方法就更加简单了,

    2、使用dos2unix工具

    dos2unix用法:

    Usage: dos2unix [options] [file ...] [-n infile outfile ...]
    -ascii convert only line breaks (default)
    -iso conversion between DOS and ISO-8859-1 character set
    -1252 Use Windows code page 1252 (Western European)
    -437 Use DOS code page 437 (US) (default)
    -850 Use DOS code page 850 (Western European)
    -860 Use DOS code page 860 (Portuguese)
    -863 Use DOS code page 863 (French Canadian)
    -865 Use DOS code page 865 (Nordic)
    -7 Convert 8 bit characters to 7 bit space
    -c, --convmode conversion mode
    convmode ascii, 7bit, iso, mac, default to ascii
    -f, --force force conversion of binary files
    -h, --help give this help
    -k, --keepdate keep output file date
    -L, --license display software license
    -l, --newline add additional newline
    -m, --add-bom add UTF-8 Byte Order Mark
    -n, --newfile write to new file
    infile original file in new file mode
    outfile output file in new file mode
    -o, --oldfile write to old file (default)
    file ... files to convert in old file mode
    -q, --quiet quiet mode, suppress all warnings
    always on in stdio mode
    -s, --safe skip binary files (default)
    -ul, --assume-utf16le Assume that the input format is UTF-16LE
    -ub, --assume-utf16be Assume that the input format is UTF-16BE
    -F, --follow-symlink follow symbolic links and convert the targets
    -R, --replace-symlink replace symbolic links with converted files
    (original target files remain unchanged)
    -S, --skip-symlink keep symbolic links and targets unchanged (default)
    -V, --version display version number

    安装dos2unix,

    $sudo apt-get install dos2unix

    对文件执行编码格式转换,

    dos2unix filename 

    多文件转换,

    dos2unix file1 file2 file3

    若需要把文件夹中所有文件都转换,在文件夹中执行

    find -type f | xargs dos2unix

    附xargs用法: 

      xargs是一条Unix和类Unix操作系统的常用命令。它的作用是将参数列表转换成小块分段传递给其他命令,以避免参数列表过长的问题。

    Usage: xargs [-0prtx] [--interactive] [--null] [-d|--delimiter=delim]
    [-E eof-str] [-e[eof-str]] [--eof[=eof-str]]
    [-L max-lines] [-l[max-lines]] [--max-lines[=max-lines]]
    [-I replace-str] [-i[replace-str]] [--replace[=replace-str]]
    [-n max-args] [--max-args=max-args]
    [-s max-chars] [--max-chars=max-chars]
    [-P max-procs] [--max-procs=max-procs] [--show-limits]
    [--verbose] [--exit] [--no-run-if-empty] [--arg-file=file]
    [--version] [--help] [command [initial-arguments]]

    附网友的解释http://blog.csdn.net/zhangfn2011/article/details/6776925

     

    -0 当sdtin含有特殊字元时候,将其当成一般字符,像/'空格等

     root@localhost:~/test#echo "//"|xargs  echo 
    
      root@localhost:~/test#echo "//"|xargs -0 echo 
    
           /

    -a file 从文件中读入作为sdtin,

    root@localhost:~/test#cat test 
    #!/bin/sh
    echo "hello world/n"
    root@localhost:~/test#xargs -a test echo
    #!/bin/sh echo hello world/n
    root@localhost:~/test#

    -e flag ,注意有的时候可能会是-E,flag必须是一个以空格分隔的标志,当xargs分析到含有flag这个标志的时候就停止。

    root@localhost:~/test#cat txt
    /bin tao shou kun
    root@localhost:~/test#cat txt|xargs -E 'shou' echo
    /bin tao
    root@localhost:~/test#

    -p 当每次执行一个argument的时候询问一次用户。

    root@localhost:~/test#cat txt|xargs -p echo
    
    echo /bin tao shou kun ff ?...y
    
    /bin tao shou kun ff

    -n num 后面加次数,表示命令在执行的时候一次用的argument的个数,默认是用所有的。

    root@localhost:~/test#cat txt|xargs -n1 echo
    /bin
    tao
    shou
    kun
    root@localhost:~/test3#cat txt|xargs  echo
    /bin tao shou kun

    -t 表示先打印命令,然后再执行。

    root@localhost:~/test#cat txt|xargs -t echo
    echo /bin tao shou kun 
    /bin tao shou kun

    -i 或者是-I,这得看linux支持了,将xargs的每项名称,一般是一行一行赋值给{},可以用{}代替。

    $ ls | xargs -t -i mv {} {}.bak

    -r no-run-if-empty 当xargs的输入为空的时候则停止xargs,不用再去执行了。

    root@localhost:~/test#echo ""|xargs -t mv
    mv 
    mv: missing file operand
    Try `mv --help' for more information.
    root@localhost:~/test#echo ""|xargs -t -r  mv
    root@localhost:~/test#
    (直接退出)

    -s num 命令行的最好字符数,指的是xargs后面那个命令的最大命令行字符数。

    root@localhost:~/test#cat test |xargs -i -x  -s 14 echo "{}"
    exp1
    exp5
    file
    xargs: argument line too long
    linux-2
    root@localhost:~/test#

    -L  num Use at most max-lines nonblank input lines per command line.-s是含有空格的。

    -l  同-L

    -d delim 分隔符,默认的xargs分隔符是回车,argument的分隔符是空格,这里修改的是xargs的分隔符

    root@localhost:~/test#cat txt |xargs -i -p echo {}
    echo /bin tao shou kun ?...y
    root@localhost:~/test#cat txt |xargs -i -p -d " " echo {}
    echo /bin ?...y
    echo tao ?.../bin
    y
    echo shou ?...tao
    再如:
    root@localhost:~/test#cat test |xargs -i -p -d " " echo {}
    echo exp1
    exp5
    file
    linux-2
    ngis_post
    tao
    test
    txt
    xen-3
     ?...y
    root@localhost:~/test#cat test |xargs -i -p echo {}
    echo exp1 ?...y
    echo exp5 ?...exp1
    y
    echo file ?...exp5
    y

    -x exit的意思,主要是配合-s使用。

    -P 修改最大的进程数,默认是1,为0时候为as many as it can 

  • 相关阅读:
    很老的一篇文章:李翱(伊秀女性网):从程序员到精英站长的跨度
    推荐一款很好用的CSS下拉菜单框架
    网站推广之软文写作与发布技巧
    SEO网站外链接分析工具
    图解几大浏览器的区别(搞笑)
    好文摘抄:极简生活:一来,一去
    南通搜索引擎优化:浅谈国内SEO的发展趋势
    关注程序员健康之——程序员最有效的十大戒烟方法
    [你必须知道的css系列]第一回:丰富的利器:CSS选择符之通配符、类选择符、包含选择符、ID选择符
    [你必须知道的css系列]第一回:冠冕堂皇:CSS的作用及其基本结构
  • 原文地址:https://www.cnblogs.com/righere/p/4956513.html
Copyright © 2011-2022 走看看