I usually use something like the following for submitting array jobs,
#!/bin/bash
sbatch <<EOT
#!/bin/sh
#SBATCH --job-name=$1
#SBATCH --time=$2
#SBATCH --mem-per-cpu=$3
#SBATCH --array 0-$4
./myprogram.o ${SLURM_ARRAY_TASK_ID} <-- SLURM_ARRAY_TASK_ID not visible.. (A)
./script_that_runs_myprogram.sh <-- SLURM_ARRAY_TASK_ID visible inside script (B)
EOT
In case (B), script_that_runs_myprogram.sh can see the environment variable that defines the task ID. Is it possible to access the array index somehow in case (A)? It seems unnecessary to have another script which runs the program. The alternative case where SBATCH parameters are defined manually is very tedious.