Ubuntu 中的 bash 功能不如 Redhat

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
patrickhe
帖子: 681
注册时间: 2005-07-21 19:13
来自: Peking, China
联系:

Ubuntu 中的 bash 功能不如 Redhat

#1

帖子 patrickhe » 2007-06-06 12:18

在 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 参数……
真是不爽啊!
头像
karron
帖子: 6226
注册时间: 2005-06-11 14:03
来自: 不明真相的群众
联系:

#2

帖子 karron » 2007-06-06 12:30

现在ubuntu默认是dash,而不是bash. 这样会导致很多脚本运行不正常.
我的blog,关于技术,软件,linux,vim <---- 所有博客均被河蟹.
头像
zhan
帖子: 1880
注册时间: 2005-08-15 0:04
来自: 南7技校

#3

帖子 zhan » 2007-06-06 12:33

代码: 全选

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 的原因。
飞得高,飞得低,学习再学习,多少大秘密!
http://zhan.blog.ubuntu.org.cn
dbzhang800
帖子: 3182
注册时间: 2006-03-10 15:10
来自: xi'an China
联系:

#4

帖子 dbzhang800 » 2007-06-06 12:59

ls 正解
头像
days72115
帖子: 124
注册时间: 2006-09-02 21:41
来自: 江苏南京
联系:

#5

帖子 days72115 » 2007-06-06 13:17

学习了
http://www.iviai.com.cn
C2.6/384M DDR266/Samsung80G+ST160G/MMX44064bit64M/DVD-rw
头像
patrickhe
帖子: 681
注册时间: 2005-07-21 19:13
来自: Peking, China
联系:

#6

帖子 patrickhe » 2007-06-06 14:00

第一个问题,我的脚本中写的确实是 #!/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 的原因。
头像
patrickhe
帖子: 681
注册时间: 2005-07-21 19:13
来自: Peking, China
联系:

#7

帖子 patrickhe » 2007-06-06 14:03

karron 写了:现在ubuntu默认是dash,而不是bash. 这样会导致很多脚本运行不正常.
嗯,我发现了这个问题,现在把 /bin/sh 指向了 /bin/bash。
lert
帖子: 40
注册时间: 2007-04-17 0:42

#8

帖子 lert » 2007-06-12 0:30

这种东东没有什么好不好的:如果觉得系统的bash或者其他程序没达到自己的要求,自己下源代码,按照自己的意思编译即可,这些问题与操作系统没有什么关系把。
头像
patrickhe
帖子: 681
注册时间: 2005-07-21 19:13
来自: Peking, China
联系:

#9

帖子 patrickhe » 2007-06-12 10:17

lert 写了:这种东东没有什么好不好的:如果觉得系统的bash或者其他程序没达到自己的要求,自己下源代码,按照自己的意思编译即可,这些问题与操作系统没有什么关系把。
从理论上来说,你的方法是可行的。对于任何操作系统,你的方法都是可用的。
头像
xieshaohu
帖子: 1565
注册时间: 2007-10-24 20:20
来自: 北京、海淀
联系:

Re: Ubuntu 中的 bash 功能不如 Redhat

#10

帖子 xieshaohu » 2009-07-15 14:32

学习拉。最近正在了解redhat和ubuntu的区别
Dell Vostro 1500, T7300/4GB/WD5000BEVT/nVidia 8400GM, Ubuntu 10.04 x86_64/VMware 7(Win7)
我的博客:http://xieshaohu.wordpress.com/
tusooa
帖子: 6548
注册时间: 2008-10-31 22:12
系统: 践兔
联系:

Re:

#11

帖子 tusooa » 2009-07-16 0:33

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)
>>

代码: 全选

] ls -ld //
头像
yingfei
帖子: 273
注册时间: 2007-09-03 18:34
来自: 羊城通

Re: Ubuntu 中的 bash 功能不如 Redhat

#12

帖子 yingfei » 2009-07-17 9:19

现在还流行盗墓吗? :em06
头像
Hamtaro
帖子: 308
注册时间: 2005-04-15 5:59

Re: Ubuntu 中的 bash 功能不如 Redhat

#13

帖子 Hamtaro » 2009-07-20 21:15

挖一下... 希望早日成为摸金校卫... :em06
AMD Althon64X2 Dual Core Processor 5000+
Jetway Hammar A770
Segate SATA 160G + Segate ATA 80G
Geil DDR2-800 2048 MB
AOC2016SW 1650x1050 with Geforce 9600GT

Windows XP sp3 & ubuntu 10.10
回复