Re: Why is bash not behaving consistently?

From: Paul Howarth (paul_at_city-fan.org)
Date: 08/12/05

  • Next message: Vikram Goyal: "rpm being treated as [audio/x-pn-realaudio-plugin]"
    Date: Fri, 12 Aug 2005 12:44:55 +0100
    To: For users of Fedora Core releases <fedora-list@redhat.com>
    
    

    Dan Track wrote:
    > On 8/12/05, Stephanus Fengler <fengler@uiuc.edu> wrote:
    >
    >>Paul Howarth wrote:
    >>
    >>
    >>>Dan Track wrote:
    >>>
    >>>
    >>>>I was writing this little bash script using find and I came along this
    >>>>difference from using the same command on the command line and in bash
    >>>>script.
    >>>>
    >>>>Basically on the command line I have to type:
    >>>>
    >>>>/usr/bin/find /opt/yum/packages/ -mtime +2 -a \( -regex .*.rpm -o
    >>>>-regex .*.hdr \) -exec ls -lrt {} \;
    >>>>
    >>>>whereas , in a bash script I have to type:
    >>>>
    >>>>/usr/bin/find /opt/yum/packages/ -mtime +2 -a ( -regex .*.rpm -o
    >>>>-regex .*.hdr ) -exec ls -lrt {} ;
    >>>>
    >>>>As you can see I need to escape parenthesis and semi-colons on the
    >>>>command line but I don't need to do that in a bash script.
    >>>>
    >>>>Is there a reason for this?
    >>>
    >>>
    >>>How are you running this script? I would expect the first version to
    >>>work on the command-line and in a script, and the second version not
    >>>to work at all...
    >>>
    >>>Paul.
    >>>
    >>
    >>Maybe your standard script interpreter isn't bash but simply sh? You may
    >>add
    >># /bin/bash
    >>
    >>as your first line to make sure bash is used.
    >>
    >>Stephanus
    >
    >
    > The script interpreter is /bin/bash.

    Can't reproduce this here.

    With this script:

    #!/bin/bash

    /usr/bin/find /var/cache/yum/updates-released/packages/ -mtime +2 -a \(
    -regex .*.rpm -o -regex .*.hdr \) -exec ls -lrt {} \;

    I get output:

    -rw-r--r-- 1 root root 9763596 Aug 1 00:00
    /var/cache/yum/updates-released/packages/evolution-2.2.3-2.fc4.i386.rpm
    -rw-r--r-- 1 root root 91382 Aug 1 00:00
    /var/cache/yum/updates-released/packages/evolution-devel-2.2.3-2.fc4.i386.rpm

    With this script:

    #!/bin/bash

    /usr/bin/find /var/cache/yum/updates-released/packages/ -mtime +2 -a (
    -regex .*.rpm -o -regex .*.hdr ) -exec ls -lrt {} ;

    I get the expected errors:

    ./run_yum_clean: line 5: syntax error near unexpected token `('
    ./run_yum_clean: line 5: `/usr/bin/find
    /var/cache/yum/updates-released/packages/ -mtime +2 -a ( -regex .*.rpm
    -o -regex .*.hdr ) -exec ls -lrt {} ;'

    I'd also suggest escaping the asterisks, so in your original script that
    would be:

    /usr/bin/find /opt/yum/packages/ -mtime +2 -a \( -regex .\*.rpm -o
    -regex .\*.hdr \) -exec ls -lrt {} \;

    What output do you get from this, and what output from your unescaped
    script?

    Paul.

    -- 
    fedora-list mailing list
    fedora-list@redhat.com
    To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list
    

  • Next message: Vikram Goyal: "rpm being treated as [audio/x-pn-realaudio-plugin]"