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 ...]
3
  • 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)) Commented Nov 11, 2015 at 8:39
  • @mikeserv: Would you please linking me to the source indicate that set -A is deprecated. Commented Nov 11, 2015 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. Commented Nov 11, 2015 at 9:03

1 Answer 1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.