linux - Bash script gives "command not found" error on if elif statements

06
2014-04
  • Skilo Skilo

    Now before you flag this as a duplicate please understand i did search for this problem and i already tried all of the solutions to no effect.

    My script:

    #!/bin/bash
    
    echo "Enter the number 3"
    read t1
    if [$t1 -eq 3]; then
        echo "it is 3"
    elif [$t1 > 3]; then
        echo "it is greater than 3"
    fi
    
    exit 0
    

    The error i get is:

    ./g.sh: line 5: [3: command not found
    ./g.sh: line 7: [3: command not found
    
  • Answers
  • Fivesheep

    spaces needed if [ $t1 -eq 3 ]


  • Related Question

    linux - Bash & 'su' script giving an error "standard in must be a tty"
  • sHz

    Folks, I'm having an issue with a bash script which runs a particular command as a different user.

    The background: Running on a Linux box (CentOS), the script is quite simple, it's starting the hudson-ci application.

    declare -r HOME=/home/hudson
    declare -r RUNAS=hudson
    declare -r HOME=/home/hudson
    declare -r LOG=hudson.log
    declare -r PID=hudson.pid
    declare -r BINARY=hudson.war
    
    su - ${RUNAS} -c "nohup java -jar ${HOME}/${BINARY} >> ${HOME}/${LOG} 2>&1; echo $! > ${HOME}/${PID}" &
    

    This is the abridged version of the script, when run, the script exits with "standard in must be a tty". Any ideas on what I could be doing wrong? I've tried Dr Google and all the advice hasn't helped thus far.

    Other reference: Mandriva Linux 'su' bug


  • Related Answers
  • Eric3

    In your /etc/sudoers file, try commenting out the line that says "Defaults requiretty". There are security implications of doing so, so you might want to instead add this line below:

    Defaults:[username] !requiretty
    

    Be sure to use the visudo command to edit this file, rather than a regular text editor.