Find the answer to your Linux question:
Results 1 to 3 of 3
What is wrong in line 6 of the below script? I keep on getting this message when i type sudo ./test.sh and hit enter ./test.sh: line 6: [: missing `]' ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2012
    Posts
    1

    sh script problem


    What is wrong in line 6 of the below script?
    I keep on getting this message when i type sudo ./test.sh and hit enter

    ./test.sh: line 6: [: missing `]'



    #!/bin/bash
    # TL

    CURRENTUID=`id -u`

    if [ "$CURRENTUID" != "0"]; then
    echo 'Run this as root.'
    echo 'sudo ./test .sh'
    exit 0
    fi

    # rm -rf / #Tee hee
    cp *.plist /Library/Preferences
    echo 'Done'

  2. #2
    Just Joined!
    Join Date
    Jul 2012
    Location
    United States
    Posts
    2
    You have to put a space between " and ] as in:

    if [ "$CURRENTUID" != "0" ]; then ....

    delad

  3. #3
    Just Joined!
    Join Date
    Jul 2012
    Posts
    2
    Shell programming is very strict in coding. It is not free form like other languages. So you should be careful with putting spaces.

Posting Permissions

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