Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Bash "function { }" call ignored.... ?

  1. #1
    Join Date
    Aug 2005
    Location
    Canada
    Beans
    259
    Distro
    Kubuntu 11.04 Natty Narwhal

    Bash "function { }" call ignored.... ?

    Any idea why this will work on a Redhat system, but not on my Kubuntu?

    It's like it doesn't understand the function { } at all..... It should go right to the case and only use the function when called. Instead it dies right away with:

    This is the first choice
    test: 9: Syntax error: "}" unexpected


    #!/bin/bash

    function first {

    clear

    echo "This is the first choice"

    }

    function second {

    clear

    echo "This is the second choice"

    }

    clear

    echo "What do you want to do?"
    echo
    echo "1 Print the first message"
    echo "2 Print the second message"
    echo "3 Quit"

    read pick

    case $pick in
    1 ) first;;
    2 ) second;;
    3 ) exit;;

    esac
    -OG-

  2. #2
    Join Date
    Apr 2008
    Location
    Phoenix, AZ
    Beans
    1,393
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Bash "function { }" call ignored.... ?

    I think your functions should look like this


    Code:
    function () {
    
     <do something>
    
    }
    Doesn't seem that you are passing any variables so just "()" is sufficient.

  3. #3
    Join Date
    Mar 2007
    Location
    Manchester, UK
    Beans
    101
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Bash "function { }" call ignored.... ?

    That worked for me in Ubuntu.

    One issue I came across recently was running scripts, under cron for example, sometimes forces dash not bash.

    I don't know where you're running what, or how Kubuntu differs to suggest more..

  4. #4
    Join Date
    Oct 2007
    Location
    Siberia
    Beans
    217
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Bash "function { }" call ignored.... ?

    No clue.

    Just copypasted it in gedit and ran. Everything works. There could be brackets after function names (e.g. function first () {...), but for me it runs anyway.

    What's your bash version?
    Code:
    $ /bin/bash --version
    GNU bash, version 3.2.33(1)-release (i486-pc-linux-gnu)
    Copyright (C) 2007 Free Software Foundation, Inc.
    Registered Ubuntu User # 18873.
    We all create a new world.

  5. #5
    Join Date
    Aug 2005
    Location
    Canada
    Beans
    259
    Distro
    Kubuntu 11.04 Natty Narwhal

    Re: Bash "function { }" call ignored.... ?

    Quote Originally Posted by Monicker View Post
    I think your functions should look like this


    Code:
    function () {
    
     <do something>
    
    }
    Doesn't seem that you are passing any variables so just "()" is sufficient.

    Nope.... If I add () I get:

    test: 3: Syntax error: "(" unexpected
    -OG-

  6. #6
    Join Date
    Apr 2008
    Location
    Phoenix, AZ
    Beans
    1,393
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Bash "function { }" call ignored.... ?

    Quote Originally Posted by OldGaf View Post
    Nope.... If I add () I get:
    Hrmm. It worked for me using Ubuntu 7.10.

    I copied and posted from your first post, and just added the () to each function.

    Code:
    arkaic@purgatory:/tmp$ ./function.sh
    
    
    
    
    What do you want to do?
    
    1 Print the first message
    2 Print the second message
    3 Quit
    1
    
    
    
    
    
    This is the first choice
    arkaic@purgatory:/tmp$

    Code:
    arkaic@purgatory:/tmp$ bash --version
    GNU bash, version 3.2.25(1)-release (i486-pc-linux-gnu)
    Copyright (C) 2005 Free Software Foundation, Inc.

    Maybe it really is something different about kubuntu.

  7. #7
    Join Date
    Aug 2005
    Location
    Canada
    Beans
    259
    Distro
    Kubuntu 11.04 Natty Narwhal

    Re: Bash "function { }" call ignored.... ?

    Quote Originally Posted by rubicon View Post
    No clue.

    Just copypasted it in gedit and ran. Everything works. There could be brackets after function names (e.g. function first () {...), but for me it runs anyway.

    What's your bash version?
    Code:
    $ /bin/bash --version
    GNU bash, version 3.2.33(1)-release (i486-pc-linux-gnu)
    Copyright (C) 2007 Free Software Foundation, Inc.

    Sigh.... and it works at work... (actually a much larger script, this is just a test to figure this out)

    How did you run it.... sh <filename> ?
    -OG-

  8. #8
    Join Date
    Mar 2007
    Location
    Manchester, UK
    Beans
    101
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Bash "function { }" call ignored.... ?

    ./filename
    having made it executable obviously..

  9. #9
    Join Date
    Mar 2007
    Location
    Manchester, UK
    Beans
    101
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Bash "function { }" call ignored.... ?

    Trying
    sh ./filename
    just gave the error you had initially.

  10. #10
    Join Date
    Mar 2007
    Location
    Manchester, UK
    Beans
    101
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Bash "function { }" call ignored.... ?

    and reading briefly man sh suggests it uses dash.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •