Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Below shell script instruction behave in weird way

select convert(varchar, PRIOR_COB_DATE, 112) from TABLE
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
        echo "assigned " $PRIOR_POSITION_DATE
        echo "Date must be in follow format: YYYYMMDD"
        echo "POSITION_DATE will be used."

    echo $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
        #    rm ${CONNECTION_STATUS_FILE}

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.


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
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:

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
@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.