0

I have the below bash script, but rather that I get the command executed stored in cmd[1] it prints [1]: command not found. I executed the command with the following way:

$ qsub -J 1-33 sicer-pbs.sh



#!/bin/bash

# Usage: qsub -J 1-33 sicer-pbs.sh

#PBS -N sicer
#PBS -l select=1:ncpus=1:mem=8G
#PBS -l walltime=30:00:00


# Generic PBS commands

source /usr/share/modules/init/bash;
module load python;

sleep $(( ($PBS_ARRAY_INDEX % 10) * 15 ));

cmd[1]="sh /usr/local/SICER_V1.1/SICER/SICER.sh /home/lorencm/bed/B1-C1-C7/ /home/lorencm/bed/B1-C1-C7/0000-C1.single.bed /home/lorencm/bed/B1-C1-C7/0006-C7.single.bed /home/lorencm/bed/B1-C1-C7/output btryoni 1 200 150 0.739196477788 600 0.01"


echo $cmd[$PBS_ARRAY_INDEX]
$cmd[$PBS_ARRAY_INDEX]

What did I do wrong?

  • 2
    You should use brackets when accessing elements of an array - ${cmd[...]}. $cmd[$PBS_ARRAY_INDEX] is equivalent to ${cmd[0]}[$PBS_ARRAY_INDEX] – adonis May 25 '16 at 0:56
  • The short answer is that you should use eval "$cmd[$PBS_ARRAY_INDEX]" A full answer and explanation can be found here stackoverflow.com/questions/4668640/… – Argonauts May 25 '16 at 1:57
  • @adonis is correct. Plus array[ ] does arithmetic expansion so you don't need $: ${cmd[PBS_ARRAY_INDEX]} is enough. $(( )) also. – dave_thompson_085 May 25 '16 at 4:58
  • @dave_thompson_085, great - I didn't know that! Thanks – adonis May 25 '16 at 4:59
  • Also, you are setting cmd[1], but using ${cmd[$PBS_ARRAY_INDEX]}. that will only work if $PBS_ARRAY_INDEX == 1. – cas May 25 '16 at 7:23

Your Answer

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

Browse other questions tagged or ask your own question.