Daniel Del Core
Daniel Del Core

Reputation: 3221

Syntax Error in simple bash script

Hello im new to bash scripting, i have a simple program which is not working for me. I assume its a syntactical error.

#!/bin/bash
#example1.sh
read Age
if ["$Age" -lt "18"]; then
    echo "You must go to school"
fi

When i input a 1 it says [1: command not found

Upvotes: 0

Views: 129

Answers (2)

davidstar
davidstar

Reputation: 218

#!/bin/bash
#example1.bash

read Age
if(($Age < 18)); then
echo "You must go to school"
fi

This code works when it is run in bash. Bash and sh are not completely the same.

Upvotes: 0

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272447

You need spaces:

if [ "$Age" -lt "18" ]; then

(Summary: Bash syntax rules are appalling.)

Upvotes: 6

Related Questions