$$# is evaluating to 1 when no value

I have the following in my makefile:

    RESULT=`../${TOOLS_ROOT_PATH}/ext_tools.sh 11`; \
    set $$RESULT > tMp; \
    rm tMp; \
    if [ $$# -ne 0 ]; then \
        echo copying external-local tool: $< \($$*\); \
        mkdir -p ${EXTERNAL_LOCAL_BIN_DIR}/$<; \
        cp -f `../${TOOLS_ROOT_PATH}/ext_tools.sh 11` ${EXTERNAL_LOCAL_BIN_DIR}/$< || exit $$?;\
        if [ -f $<"-install-script" ]; then \
            echo copying $<"-install-script"; \
            mkdir -p ${EXTERNAL_LOCAL_BIN_DIR}/install-scripts; \
            cp -f $<"-install-script" ${EXTERNAL_LOCAL_BIN_DIR}/install-scripts; \
            chmod +x ${EXTERNAL_LOCAL_BIN_DIR}/install-scripts/$<"-install-script"; \
        fi; \
    fi; \
    set `../${TOOLS_ROOT_PATH}/ext_tools.sh 12` > tMp; \
    if [ $$# -ne 0 ]; then \
        echo copying external-remote tool: $< \($$*\); \
        mkdir -p ${EXTERNAL_REMOTE_BIN_DIR}/$<; \
        cp -f `../${TOOLS_ROOT_PATH}/ext_tools.sh 11` ${EXTERNAL_REMOTE_BIN_DIR}/$< || exit $$?;\
        if [ -f $<"-install-script" ]; then \
            echo copying $<"-install-script"; \
            mkdir -p ${EXTERNAL_REMOTE_BIN_DIR}/install-scripts; \
            cp -f $<"-install-script" ${EXTERNAL_REMOTE_BIN_DIR}/install-scripts; \
            chmod +x ${EXTERNAL_REMOTE_BIN_DIR}/install-scripts/$<"-install-script"; \
        fi; \
    fi; \
    rm tMp; \

When ext_tools.sh returned nothing, the $$# in the second if-condition is evaluating to 1. Any idea why it is happening is much appreciated.

+ .././makefiles/tools/ext_tools.sh 11
RESULT=test_tool1
+ set test_tool1
+ rm tMp
+ [ 1 -ne 0 ]
+ echo copying external-local tool: test_tool1 (test_tool1)
copying external-local tool: test_tool1 (test_tool1)
+ mkdir -p /tmp/lmcsrpe/ggsn_ttx/external/local/bin/ttx/external/test_tool1
+ .././makefiles/tools/ext_tools.sh 11
+ cp -f test_tool1 /tmp/lmcsrpe/ggsn_ttx/external/local/bin/ttx/external/test_tool1
+ [ -f test_tool1-install-script ]
+ .././makefiles/tools/ext_tools.sh 12
+ set
+ [ 1 -ne 0 ]
+ echo copying external-remote tool: test_tool1 (test_tool1)
copying external-remote tool: test_tool1 (test_tool1)
+ mkdir -p /tmp/lmcsrpe/ggsn_ttx/external/remote/bin/ttx/external/test_tool1
+ .././makefiles/tools/ext_tools.sh 11
+ cp -f test_tool1 /tmp/lmcsrpe/ggsn_ttx/external/remote/bin/ttx/external/test_tool1
+ [ -f test_tool1-install-script ]
+ rm tMp

Thanks

What do you expect it to be? I think that in your context $$# is the number of positional parameters passed to the script.
I'm also puzzled by the "set" commands and what you expect them to be doing.:confused:

Hi JerryHone, thanks for the reply.

I thought by doing `set $$RESULT`, I would get the number of words returned by ext_tools.sh by using $$#.. Am I wrong?

The redirection to tMp was because when ext_tools.sh returned nothing, `set $$RESULT` is printing out all the env variables onto the console which I wanted to avoid.

Franklin52, thanks for editing with codetags. I 'll remember that next time...

"set" isn't used in Bourne/Korn shells for setting variables. It's a long time ago, but I think it's C shell syntax! On its own in Bourne/Korn, it just outputs the entire environment, which I think is what you saw.
$RESULT will be the STDOUT output from the ext_tools call. If you want the number of words returned, use something like

NWORDS=`echo $$RESULT | wc -w`

Thanks JerryHone... for clearing the puzzle. Appreciate it.