I want to pass directory as a command line argument to the shell script.
#!/bin/bash
sourcedir=/home/dir/data
cd $sourcedir
find "$PWD" -maxdepth 2 -name \*_R1*.fastq.gz > list1
fastq_list=$sourcedir/list1 echo `cat $fastq_list` num_files=$(wc -l <
$sourcedir/list1) echo $num_files
cat > run_array_job.sh<<'EOF'
#!/bin/bash -l
#$ -j y
#$ -cwd -S /bin/sh
#$ -l h_vmem=10G
#$ -pe smp 12
if [ -z "${SGE_TASK_ID}" ]; then echo "Need to set SGE_TASK_ID" exit 1 fi
BASEDIR=/home/dir/data
echo "BASEDIR" echo $BASEDIR
BASEFILES=$( ls *_R1.fastq.gz)
BASEFILES_ARRAY=(${BASEFILES})
BASEFILE=${BASEFILES_ARRAY[(${SGE_TASK_ID} - 1)]}
echo $BASEFILE
...................
...................
EOF
qsub -t 1-${num_files} run_array_job.sh
This array script for SGE cluster is script.sh and I am running it using
bash script.sh
However I want to pass the directory which is /home/dir/data from the command line such as below (instead of using it twice in the script)
bash script.sh /home/dir/data
I am not able to do that.
fastq_list=$sourcedir/list1 echo ...
line will give you a syntax error, is that really what you want? ii) don't usefoo=$( ls *_R1.fastq.gz)
, usebasefiles=( *_R1.fastq.gz )
instead. This will give you an array directly. iii) as a general rule, avoid using ALLCAPS variable names in shell scripts since by convention, environment variables are in caps. iv) It looks like you might be interested in our sister site: [bionformatics.se]. – terdon Mar 12 '19 at 17:47sourcedir=/home/dir/data
tosourcedir="$1"
and launch your script withbash script.sh /home/dir/data
. – terdon Mar 12 '19 at 18:03