I use this portion of code to set default values in my config on my script.sh

# Copyright (c) 2015 
# Licence MIT ( http://choosealicense.com/licenses/mit/ ).

typeset -A config # init array
config=( # set default values in config array
    # chemin du dossier de log
    # chemin du dossier local 

when i launch my script with shell console everything is OK and working But if I want to schedule launch with crontab i get an error

/var/********/script.sh: 148: /var/********/script.sh: typeset: not found
/var/********/script.sh: 149: /var/********/script.sh: Syntax error: "(" unexpected

here is my crontab line

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.


* * * * * root /var/********/script.sh -c file.conf > /dev/null 2> /var/********/errors.log

can you explain me why ? thanks

  • 1
    How is your cron job invoking the script? Does the script have a she-bang line? – Jeff Schaller Oct 19 '18 at 16:10
  • sorry, i've updated the post – J.D Oct 19 '18 at 16:14
  • i'm sorry but i don't know what is she-bang line... I'm a noob on shell scripting – J.D Oct 19 '18 at 16:23
  • Is that the entire script? Or is the first line something like #!/bin/sh ? – Jeff Schaller Oct 19 '18 at 16:25
  • no, the script lines are only a small portion concerned by the error (typeset ...) and the crontab has some lines befor my cron call (for cron daily reports or system things i guess) – J.D Oct 19 '18 at 16:27

Your script is assuming that it's running under a shell that supports arrays, such as bash or ksh. The lack of a she-bang line means that cron (by default) would invoke /bin/sh to execute the script. Specifically setting SHELL=/bin/sh in the crontab enforces this behavior.

If you're using bash interactively, specify bash as the she-bang line -- the first line must be:


not the second line or subsequent lines.

Alternatively, specifically invoke bash in the cron job, either by setting:


or with:

* * * * * root bash -c "/var/********/script.sh -c file.conf > /dev/null 2> /var/********/errors.log"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.