0

e made a bash script as follows:

#! /bin/bash


OUTDIR=".//DATA/share/pipelines/results/"
INDIR="./DATA/share/pipelines/test_data/infile/"
projectname=$1
input_bam=$2
bins=$3

mkdir OUTDIR || true

of="${OUTDIR}"
ind="${INDIR}"


./DATA/share/pipelines/script.R \
    -b "${bins}" \
    -c "${projectname}" \
    -o "${of}" \
    -i "${ind}"

echo "first step is done"

when I run the script using the following command:

bash first.sh 30 beh

I will get this error:

mkdir: cannot create directory ‘OUTDIR’: File exists
first.sh: line 17: ./DATA/share/pipelines/script.R: No such file or directory
first step is done

do you know how to solve the problem?

4
  • I am not sure why you are giving . in starting of paths. In case they are Absolute path you should NOT use it. Please try to remove them once and try. Fair warning I haven't tested anything on this. Commented Jun 11, 2019 at 13:44
  • @RavinderSingh13: then this would be the error: mkdir: cannot create directory ‘OUTDIR’: File exists first.sh: line 17: /DATA/share/pipelines/PIPELINES/QDNAseqFlow/QDNAseqFlow-versionMay2019/QDNAseq_BAM2CopyNumbers_parallel.R: Permission denied first steo is done Commented Jun 11, 2019 at 13:48
  • Right, if you see carefully your previous error was different than current one. See current error carefully seems file which you are trying to present its already there. Its like you need to handle this condition programatically. May be put a condition to check existance of file or directory and as per that it will act and should not give any error then. Commented Jun 11, 2019 at 13:53
  • shellcheck.net please, and then repost or delete as appropriate. Good luck. Commented Jun 11, 2019 at 14:33

1 Answer 1

1

When you call

bash first.sh 30 beh

$1 holds 30, $2 holds beh and $3 is not defined.

input_bam ist set to $2 but is never used.

With [ ! -d ${OUTDIR} ] you should be able to test if the directory exists.

#! /bin/bash

#Please check if it should be
# relative to the current working directory (starting with './')
# or absolute (starting with '/')
BASEDIR="/DATA/share/pipelines/" #"./DATA/share/pipelines/"
OUTDIR=${BASEDIR}"results/"
INDIR=${BASEDIR}"test_data/infile/"
projectname=$1
input_bam=$2  #This is never used
bins=$3  #This is not defined when callin >bash first.sh 30 beh<

[ ! -d ${OUTDIR} ] && mkdir ${OUTDIR} #Think you would create ${OUTDIR}

of="${OUTDIR}"
ind="${INDIR}"


./DATA/share/pipelines/script.R \
    -b "${bins}" \
    -c "${projectname}" \
    -o "${of}" \
    -i "${ind}"

echo "first step is done"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.