1

I wrote a script whilst on ubuntu 12.04.5 which ran through fine however after upgrading to 14.04.2 to fix another issue i am now having issues with the script.

It is halting at the first set of commands and i cannot seem to identify why; i made amendments based on google results however each change results in more errors.

The part of the script its currently stalling at is

#!/bin/bash

V=1.5.4

DELAY=3

if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2

    sleep 5
   exit 1

fi

while [[$REPLY != 0 ]]; do

    clear

    cat <<- _EOF_

        Please Select:

        1. Menu option 1
        2. Menu option 2
        3. Menu option 3
        4. Menu option 4
        5. Menu option 5
        6. Menu option 6
        7. Menu option 7
        0. Exit

    _EOF_
    read -p "Enter selection [0-7] >"

if [[ $REPLY =~ ^[0-7]$ ]]; then

        if [[ $REPLY == 1 ]]; then 

When I run the above script using sudo ./config.sh I receive the error

./config.sh: line 23 [[: command not found

When i remove the extra brackets i receive the error

./config.sh: line 23: [: !=: unary operator expected

In the full script the line containing while [[$REPLY != 0 ]]; do is line 23

Adding quotes to $Reply also results in the same error.

I don't understand what has changed within bash since upgrading to the newer LTS. Any help would be appreciated.

2
  • Could you make the code block containing all of your script's text? Looks horrible... Just indent all of the lines (even the empty ones).
    – setempler
    Feb 24, 2015 at 16:03
  • Also note that its better to use while [[ $REPLY -ne 0 ]] while comparing numerics..
    – heemayl
    Feb 24, 2015 at 16:16

1 Answer 1

3

You missed a space between [[ and $REPLY:

while [[$REPLY != 0 ]]; do

should be

while [[ $REPLY != 0 ]]; do
2
  • I appreciate the quick responses to this; i cannot believe it was as simple as adding a space between the brackets and the variable.
    – Craig
    Feb 24, 2015 at 19:25
  • You are welcome, and I would appreciate if you accept my answer if it solved your problem (click on the tick below the vote up/down arrows on the left).
    – setempler
    Feb 24, 2015 at 21:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .