Bossjara
Bossjara

Reputation: 43

make directory with two bash variable as shown below, what's wrong?

Can't make directory with the following bash script:

##! /bin/bash
PROJ=~/myname
for i in  aa bb cc
do
TMPDIR=${PROJ}/${i}
test ! -e ${TMPDIR} &&  mkdir ${TMPDIR}
OUTDIR=${PROJ}/${i}/subfolder
test ! -e ${OUTDIR} &&  mkdir ${OUTDIR}

/bin/cp -f ./file.out ${OUTDIR}/
done 

It turns out the OUTDIR dose not exist! What's wrong, and how do I make directory with two bash variable?

thanks in advance.

Upvotes: 0

Views: 45

Answers (1)

user1934428
user1934428

Reputation: 22225

And you did not get any error message, that a directory can not be created? After all, your script would fail if the the directory $HOME/home does not exist.

You could simplify the creation process to

PROJ="$HOME/home"
for i in  aa bb cc
do
  OUTDIR="$PROJ/$i/subfolder"
  mkdir -p "$OUTDIR" && cp -f ./file.out "$OUTDIR" && echo "File copied to $OUTDIR"
done

Upvotes: 1

Related Questions