life00 / awecron.sh

small and simple cron that is the best option for desktop users
MIT License
3 stars 3 forks source link

Shell syntax #4

Closed kurahaupo closed 2 years ago

kurahaupo commented 2 years ago

The following syntax is an unportable extension:

function main() {

Use either function or (), not both.

life00 commented 2 years ago

ok, i have no idea what that () is for so then i will change that to

function main {
kurahaupo commented 2 years ago

The "original" way to declare a function was with empty parentheses; this was established circa 1978:

funcname () {
  body
  commands
  here
}

The function keyword was a latter addition, circa 1987:

function funcname {
  body
  commands
  here
}

There are pro's and con's both ways.

As an extension, Bash allows any compound statement as the body, not just a brace group, so you can write:

check_thing ()
  if (( want_thing ))
  then make thing
  else rm thing
  fi

without curly brackets, or

do_stuff_in_subshell() (
  these commands run in a subshell
)

without curly brackets.