I'm trying to echo the new directory that I'm creating in the script.
BACKUP_DIR=`mkdir /tmp/"$TICKET_NUM"_EAR_BACKUP_"$(date "+%Y%m%d")"`
echo $BACKUP_DIR
But, the newly created directory is echoed in the screen. Anything Im missing here?
I'm trying to echo the new directory that I'm creating in the script.
BACKUP_DIR=`mkdir /tmp/"$TICKET_NUM"_EAR_BACKUP_"$(date "+%Y%m%d")"`
echo $BACKUP_DIR
But, the newly created directory is echoed in the screen. Anything Im missing here?
mkdir -v seems to print out the created directory, whereas mkdir is completely silent on my systems (tested on Mac OS X and Ubuntu Linux). However, you still need to parse out the directory name from this output:
mkdir /tmp/foo
(no output)
mkdir -v /tmp/foo
mkdir: created directory `/tmp/foo'
DIR=$(mkdir -v /tmp/foo | cut -d\ -f4- | tr -d "'\`")
echo $DIR
/tmp/foo
So in your case:
BACKUP_DIR=$( mkdir /tmp/"$TICKET_NUM"_EAR_BACKUP_"$(date "+%Y%m%d")" | cut -d\ -f4- | tr -d "'\`" )
/tmp will exist on MOST machines, but sometimes things can really be screwed up...).var=`cmd` catches output of cmd and stores in $var. But mkdir outputs nothing on success, so $BACKUP_DIR is empty.
BACKUP_DIR="/tmp/"$TICKET_NUM"_EAR_BACKUP_"$(date "+%Y%m%d")
mkdir $BACKUP_DIR
echo $BACKUP_DIR
This should work.