栏目:操作系统(<--点此查看更多)与 Java 开发和发布相关的操作系统知识,主要倾向 Linux
  • Shell脚本执行时出现declare: not found的解决方法

  • Sun Nov 11 07:55:38 CST 2012 编程者 我要收藏(...) 评论 ...
  • 重点看红色字体部分,可以看到,初始是/bin/sh是到/bin/dash的链接。修改后为到/bih/bash的链接。
  • 错误现象:

    deployer@andy-VirtualBox:~/pds/EB$ sh build.sh
    build.sh: 18: build.sh: declare: not found

    build.sh: 25: build.sh: declare: not found

    build.sh: 32: build.sh: declare: not found

    原因分析:

    root@andy-VirtualBox:/home/deployer/pds/EB# file /bin/sh
    /bin/sh: symbolic link to `dash'
    root@andy-VirtualBox:/home/deployer/pds/EB# file /bin/dash
    /bin/dash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x5d23ca7cbab4993f295d1089b4860eb32d406fab, stripped
    root@andy-VirtualBox:/home/deployer/pds/EB# file /bin/bash
    /bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xf199a4a89ac968c2e0e99f2410600b9d7e995187, stripped
    root@andy-VirtualBox:/home/deployer/pds/EB# ln -s /bin/bash /bin/sh
    ln: failed to create symbolic link `/bin/sh': File exists
    root@andy-VirtualBox:/home/deployer/pds/EB# ln -s /bin/bash /bin/sh -f
    root@andy-VirtualBox:/home/deployer/pds/EB# file /bin/sh
    /bin/sh: symbolic link to `/bin/bash'

    重点看红色字体部分,可以看到,初始是/bin/sh是到/bin/dash的链接。修改后为到/bih/bash的链接。
    所以,问题出在,我们的脚本是bash的脚本。而用dash去执行。虽然dash和bash都是shell,在执行时还是有差别的。

    解决方法:
    (1)执行时由sh build.sh变成bash build.sh可以解决此问题。
    (2)ln -s /bin/bash /bin/sh -f
    (3)sudo dpkg-reconfigure dash 进行配置,道理同(2)
    归结来说,为两种方式。以上两种方法都可以实现。
  • 信息来源:http://bianchengzhe.com (举报这篇文章)
  • 好评(...) 中评(...) 差评(...)