0

Hi I'm new to bash but I wanted to create a function that greeted a user differently based on the number of arguments they gave.

When I try it out I get this error: hello.sh:8: parse error near `}'

I was wondering what I was doing wrong here. however this is my code:

#!/bin/bash
greet() {
  if [["$#" -eq 1]]; then
  echo hello, $1

  else
  echo single argument only
}

I wanted it to say hello if a user entered their name but say single argument only if a user entered a string separated by a space. for example

$greet John
hello, John
$greet John smith
single argument only

would the issue be a part of my if statement?

Victor_G
  • 27
  • 1
  • 7

0 Answers0