Please Correct My script

###############
#filename.sh
###############

CUREENT_DATE=02

log_file_path="$CUREENT_DATE"-"${0##%*/}`|cut -d "." -f1|awk -F "/" '{print $NF}'`"".log"

echo $log_file_path

################
#output required

02-filename.log

Hi mohitmehral,
Find below the code

CUREENT_DATE=02 
log_file_path="$CUREENT_DATE"-"`echo $0 | awk -F"/" '{print $2}' | awk -F"." '{print $1}'`".log"" 
echo $log_file_path
CUREENT_DATE=02
log_file_path="${CUREENT_DATE}-"`basename $0 .sh`".log"
echo $log_file_path
1 Like

Thanks every1 for quick response. Now I have multiple options to get desired output

Use ${0##*/} instead of ${0##%*/}

not working.
Are you using bash shell

What isn't working?

---------- Post updated at 10:14 ---------- Previous update was at 10:08 ----------

Try:

filename=${0##*/}
logname="$CUREENT_DATE-${filename%.*}.log"

You can use this command to include the whole path..

logname="${0%/*}/$CUREENT_DATE-${filename%.*}.log"
1 Like