1
if [ $UNITS = day ]; then

   while ((OFFSET > 0)); do
      if (( OFFSET >= day )) ;then
         month=$((month - 1))
         if (( month == 0 )) ;then
            year=$((year - 1))
            month=12
         fi
         set -A days `cal $month $year`
         OFFSET=$((OFFSET - day))
         day=${days[$(( ${#days[*]}-1 ))]}
      else
         day=$((day - OFFSET))
         OFFSET=0
      fi
   done

The above code patch is running fine in AIX but when I am trying to run the same in Linux I am getting the below error:

set: -A: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option-name] [arg ...]
  • you're trying to set an array? what shell are you using? set -A is even deprecated in ksh nowadays. looks like bash based on the BHCP stuff. do days=($(cal $month $year)) – mikeserv Nov 11 '15 at 8:39
  • @mikeserv: Would you please linking me to the source indicate that set -A is deprecated. – cuonglm Nov 11 '15 at 8:47
  • @cuonglm - cant find it now, and maybe i had it wrong anyway, but i could swear ive read several times somewhere that setting vars with set was deprecated syntax because korn intends typeset to handle all of that. – mikeserv Nov 11 '15 at 9:03
1

That's because in Linux, the default user shell is often bash, and the /bin/sh was often symlinked to /bin/bash (on Redhat base distro) or /bin/dash (on Debian and Ubuntu base distro).

Declaring array set -A is ksh syntax, first implemented in ksh88, and also supported in ksh93, pdksh and its derivatives, and zsh.

You can switch to other array syntax, which supported both by ksh and bash:

set -f # turn off globbing
days=( $(cal "$month" "$year") )

or using Stéphane Chazelas's one here.

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.