Results 1 to 5 of 5

Thread: bash script - syntax error: "(" unexpected

  1. #1
    Join Date
    Sep 2012
    Beans
    7

    bash script - syntax error: "(" unexpected

    I am trying to write a bash script that calls upon parameters in an array that are stored in a config file, the path of which is stored in /etc/environment and ~/.bash_login as VMS. The config file is sourced using the code below.


    if [ -e $VMS ]
    then
    . $VMS
    readdata
    else
    echo "file not found: "$VMS" "
    exit 0
    fi

    This all works fine if run in the terminal (which is bash) but not on boot or on login. at boot or login it exits with a "syntax error: "(" unexpected" error.

    Me feeling, given my scant knowledge of using bash script, is that at login and boot it is running a sh shell and this is the reason it is not working.

    my questions are:

    1. is the boot and login shell sh?
    2. if 1. is true can i change that or how do i change my code inorder for it to be run as bash in these environments?
    3. if the above is not the case; what am i doing wrong and how can i fix it (can i put my config arrays in different places?

    I would be very grateful for some input as i am going around in circles and searches have not yielded any obvious solution.

  2. #2
    Join Date
    Sep 2011
    Beans
    27

    Re: bash script - syntax error: "(" unexpected

    if you are a newbie and you want to learn more about shell scripting, I would recommend you to go through the site
    they have awesome tutorial for shell scripting. Writing shell scripts

  3. #3
    Join Date
    Sep 2006
    Beans
    7,472
    Distro
    Lubuntu Development Release

    Re: bash script - syntax error: "(" unexpected

    I notice that you don't have an explicit shell chosen at the beginning the first line should be either:

    Code:
    #!/bin/sh
    or

    Code:
    #!/bin/bash
    They are different. The former will be more portable to other systems and goes to dash.

  4. #4
    Join Date
    Sep 2012
    Beans
    7

    Re: bash script - syntax error: "(" unexpected

    Thanks shaktiman1234 for the info.

    The problem is that i have searched extensively and I cannot identify a solution.

    I have found that the ~/.bash_login runs in a bash shell by including:

    echo $SHELL

    in this file, so the answer to point 1. seems to be no

    cheers

  5. #5
    Join Date
    Sep 2012
    Beans
    7

    Re: bash script - syntax error: "(" unexpected

    Hi Lars Noodén,

    Sorry, the piece of code is an extract. the file is #!/bin/bash at the start.

    cheers

Tags for this Thread

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
  •