Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Below shell script instruction behave in weird way

ARG_DATE=`sqsh -S $SERVER -U $DB_USER -P $DB_PASSWORD -D dbname -h<<END
SET NOCOUNT ON
go
select convert(varchar, PRIOR_COB_DATE, 112) from TABLE
go
END`
echo $ARG_DATE

if [ "${ARG_DATE}" != "1" ] && [ "${ARG_DATE}" != " " ]; then
    if [ ${ARG_DATE/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/1} = "1" ]; then
        PRIOR_POSITION_DATE=${ARG_DATE}
        echo "assigned " $PRIOR_POSITION_DATE
    else
        echo "Date must be in follow format: YYYYMMDD"
        echo "POSITION_DATE will be used."
    fi
fi



URL_PARAMS="HttpAutosysJobExecutor/NotificationEmailGenerator.job?prior_cob_date=${PRIOR_POSITION_DATE}"
    echo $URL_PARAMS
    echo ${CONNECTION_STATUS_FILE} "http://${SERVER_ADDRESS}:${SERVER_PORT}/HTTP/${URL_PARAMS}"
        wget -o ${CONNECTION_STATUS_FILE} "http://${SERVER_ADDRESS}:${SERVER_PORT}/HTTP/${URL_PARAMS}"
        if [ -f ${CONNECTION_STATUS_FILE} ]; then
            RESPONSE_STATUS=`grep -o '200 OK' ${CONNECTION_STATUS_FILE}`
            if [ -z "${RESPONSE_STATUS}" ]; then
                echo Login failed.
                exit 3
            fi
        #    rm ${CONNECTION_STATUS_FILE}
        fi

while executing wget I am getting so many whitespaces becasue of whitespaces database procedure is failing to cast string in DB Date, using sed I can remove whitespaces but I want to know the possible reason of this.

Log in CONNECTION_STATUS_FILE

http://XXXXX:7001/MYAPP/HttpAutosysJobExecutor/NotificationEmailGenerator.job?prior_cob_date=%2020130523%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20
share|improve this question

closed as too localized by Gilles, Anthon, slm, vonbrand, psusi May 29 '13 at 13:41

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
So you have a problem with ${PRIOR_POSITION_DATE} but don't tell us how ${PRIOR_POSITION_DATE} is created / set and now we shall guess? –  Hauke Laging May 29 '13 at 9:23
    
@echo ${PRIOR_POSITION_DATE} shows, " 20130523" but there are not traling spaces. trailing spaces are issue. –  Alpesh Gediya May 29 '13 at 9:26
    
Are you really telling me that it's of no use to show us how ${PRIOR_POSITION_DATE} gets assigned its value? –  Hauke Laging May 29 '13 at 9:29
    
updated question with how i am setting value. –  Alpesh Gediya May 29 '13 at 9:33
    
And what is the output you get when running the script, assigned ... or POSITION_DATE will be used? –  Hauke Laging May 29 '13 at 9:42

1 Answer 1

up vote 1 down vote accepted

The echo Does not show you the whitespace at the end. For that you need something like echo "${URL_PARAMS}x". You can do set -x immediately before the wget call and set +x immediately after to see how wget is called.

The problem is the shell's word splitting:

${ARG_DATE/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/1} = "1"

instead of

"${ARG_DATE/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/1}" = "1"

A solution would be to put this before that (fixed) line:

ARG_DATE="${ARG_DATE// /}"
share|improve this answer
    
but just after fetching data from DB "${ARG_DATE}test" evaluted as 20130523 test –  Alpesh Gediya May 29 '13 at 10:00
    
@AlpeshGediya So what? Do you ask where the other spaces come from? Are you sure you tested that with the quotes (echo "${ARG_DATE}test")? –  Hauke Laging May 29 '13 at 10:02
    
I have never used this ARG_DATE="${ARG_DATE// /}" synatax can you please provide explanation about this in your answer.. –  Alpesh Gediya May 29 '13 at 10:07
1  
@AlpeshGediya You use nearly that in your script... The difference is that / replaces the first occurrence and // all occurrences of the string. I.e. all spaces get replaced by – nothing (i.e. deleted). –  Hauke Laging May 29 '13 at 10:22
    
@AlpeshGediya What does "failing to split" mean? –  Hauke Laging May 29 '13 at 10:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.