Can you please describe this script? - Shell Scripting

This is a discussion on Can you please describe this script? - Shell Scripting ; Hi, I am trying to understand what this query trying to do. Can you please explain this? delt_file=`diff /transfer/adx/tey_header.txt /transfer/adx/tey_header_yesterdy.txt` if [[ $delt_file == "" ]] ; then touch /transfer/adx/lrstb028_ctl2.ctl else if test -f "/transfer/adx/lrstb028_ctl2_2.ctl" ; then touch /transfer/adx/lrstb028_ctl2.ctl fi ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Can you please describe this script?

  1. Can you please describe this script?

    Hi, I am trying to understand what this query trying to do. Can you please explain this?

    delt_file=`diff /transfer/adx/tey_header.txt /transfer/adx/tey_header_yesterdy.txt`
    if [[ $delt_file == "" ]] ; then
    touch /transfer/adx/lrstb028_ctl2.ctl
    else
    if test -f "/transfer/adx/lrstb028_ctl2_2.ctl" ; then
    touch /transfer/adx/lrstb028_ctl2.ctl
    fi
    fi

  2. Re: Can you please describe this script?

    WOW!!! that is ugly (sorry if this is your code).... Here is my best shot:

    ### Do a diff on the two files ###
    delt_file=`diff /transfer/adx/tey_header.txt /transfer/adx/tey_header_yesterdy.txt`

    ### If $delt_file has no differences then create the file ****_ctl2.ctl ###
    if [[ $delt_file == "" ]] ; then
    touch /transfer/adx/lrstb028_ctl2.ctl
    else

    ### If if there are differences and the file ****_ctl2_2.ctl exists then create the file ****_ctl2.ctl ###
    ## This really doesn't make any sense, why would you create ****ctl2_2.ctl before ****_ctl2.ctl??? ##
    ## Also, why would you check to see if ****ctl2_2.ctl is created and then create ****_ctl2.ctl??? ##
    ## shouldn't it be the other way?? ##
    if test -f "/transfer/adx/lrstb028_ctl2_2.ctl" ; then
    touch /transfer/adx/lrstb028_ctl2.ctl
    fi
    fi

    This looks really ugly though. If this really is bash I would think about changing it to something like the following:

    delt_file=$(diff /transfer/adx/tey_header.txt /transfer/adx/tey_header_yesterdy.txt)
    ### '-z' means "if the value is NULL .... ###
    if [[ -z $delt_file ]]
    then
    touch /transfer/adx/lrstb028_ctl2.ctl
    ### '-e' means if the file exists ###
    elif [[ -e "/transfer/adx/lrstb028_ctl2.ctl" ]]
    then
    touch /transfer/adx/lrstb028_ctl2_2.ctl
    fi

+ Reply to Thread