分页: 1 / 1

Ubuntu 中的 bash 功能不如 Redhat

发表于 : 2007-06-06 12:18
patrickhe
在 Ubuntu 6.10 中,写个脚本

代码: 全选

str=abc
newstr=${str/a/b}
发现居然不支持字符串替换的语法。

看了一下 bash 的版本号,是
GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

而 Redhat AS4 中上面的脚本是可以运行的,而且它的 bash 版本号还更低
GNU bash, version 3.00.15(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.

還有 Ubuntu 中的 grep 居然不支持 -P 参数……
真是不爽啊!

发表于 : 2007-06-06 12:30
karron
现在ubuntu默认是dash,而不是bash. 这样会导致很多脚本运行不正常.

发表于 : 2007-06-06 12:33
zhan

代码: 全选

zhan@mylinux:~$ str=abc
zhan@mylinux:~$ newstr=${str/a/b}
zhan@mylinux:~$ echo $newstr
bbc
明显是支持的嘛。 估计楼上的写脚本的时候第一行是 #!/bin/sh , 在 ubuntu 中 /bin/sh 指向的是 dash, 所以功能可能有问题,改成 #!/bin/bash 试试看。

至于 grep 不支持 -P的问题, 刚看了一下 man

代码: 全选

      -P, --perl-regexp
              Interpret PATTERN as a Perl regular expression.
明显是有的。估计也许也是 dash 的原因。

发表于 : 2007-06-06 12:59
dbzhang800
ls 正解

发表于 : 2007-06-06 13:17
days72115
学习了

发表于 : 2007-06-06 14:00
patrickhe
第一个问题,我的脚本中写的确实是 #!/bin/bash。
不过我刚才重新测试了一下,现在是可以使用 shell 中的那个语法了。

第二个问题,你运行一下

代码: 全选

grep -P "fsdfas"
就会得到一条消息:
grep: The -P option is not supported

zhan 写了:

代码: 全选

zhan@mylinux:~$ str=abc
zhan@mylinux:~$ newstr=${str/a/b}
zhan@mylinux:~$ echo $newstr
bbc
明显是支持的嘛。 估计楼上的写脚本的时候第一行是 #!/bin/sh , 在 ubuntu 中 /bin/sh 指向的是 dash, 所以功能可能有问题,改成 #!/bin/bash 试试看。

至于 grep 不支持 -P的问题, 刚看了一下 man

代码: 全选

      -P, --perl-regexp
              Interpret PATTERN as a Perl regular expression.
明显是有的。估计也许也是 dash 的原因。

发表于 : 2007-06-06 14:03
patrickhe
karron 写了:现在ubuntu默认是dash,而不是bash. 这样会导致很多脚本运行不正常.
嗯,我发现了这个问题,现在把 /bin/sh 指向了 /bin/bash。

发表于 : 2007-06-12 0:30
lert
这种东东没有什么好不好的:如果觉得系统的bash或者其他程序没达到自己的要求,自己下源代码,按照自己的意思编译即可,这些问题与操作系统没有什么关系把。

发表于 : 2007-06-12 10:17
patrickhe
lert 写了:这种东东没有什么好不好的:如果觉得系统的bash或者其他程序没达到自己的要求,自己下源代码,按照自己的意思编译即可,这些问题与操作系统没有什么关系把。
从理论上来说,你的方法是可行的。对于任何操作系统,你的方法都是可用的。

Re: Ubuntu 中的 bash 功能不如 Redhat

发表于 : 2009-07-15 14:32
xieshaohu
学习拉。最近正在了解redhat和ubuntu的区别

Re:

发表于 : 2009-07-16 0:33
tusooa
karron 写了:现在ubuntu默认是dash,而不是bash. 这样会导致很多脚本运行不正常.
但是

代码: 全选

17/07/2009 00:33:10
tusooa (~/develop/bash)
>> /bin/sh
$ echo $SHELL
/bin/bash
$ exit
17/07/2009 00:33:22
tusooa (~/develop/bash)
>> /bin/dash
$ echo $SHELL
/bin/bash
$ exit
17/07/2009 00:33:40
tusooa (~/develop/bash)
>> /bin/bash
17/07/2009 00:33:52
tusooa (~/develop/bash)
>> exit
exit
17/07/2009 00:33:55
tusooa (~/develop/bash)
>>
不过

代码: 全选

17/07/2009 00:33:55
tusooa (~/develop/bash)
>> ls -l /bin | grep sh
-rwxr-xr-x 1 root root  833592 2009-03-02 22:23 bash
-rwxr-xr-x 1 root root  105592 2008-11-05 16:57 dash
lrwxrwxrwx 1 root root       4 2009-07-12 17:39 rbash -> bash
lrwxrwxrwx 1 root root       4 2009-07-12 17:39 sh -> dash
lrwxrwxrwx 1 root root       4 2009-07-12 17:39 sh.distrib -> bash
17/07/2009 00:35:06
tusooa (~/develop/bash)
>>

Re: Ubuntu 中的 bash 功能不如 Redhat

发表于 : 2009-07-17 9:19
yingfei
现在还流行盗墓吗? :em06

Re: Ubuntu 中的 bash 功能不如 Redhat

发表于 : 2009-07-20 21:15
Hamtaro
挖一下... 希望早日成为摸金校卫... :em06