Question:
Just trying to better understand why the second item below does not work. The first item is simple, the second seems clearer, the third seems unintuitive.
1 2 3 4 5 6 7 8 9 |
# My path includes pscp so this works. pscp.exe -i $PRIVATE_KEY $file ${PROXY_USER}@${PROXY_HOST}:${PROXY_DIR} # This does not work. I get unexpected token error. Why? What does that mean? $PUTTY_PATH\pscp.exe -i $PRIVATE_KEY $file ${PROXY_USER}@${PROXY_HOST}:${PROXY_DIR} # & is required to solve the problem. & "$PUTTY_PATH\pscp.exe" -i $PRIVATE_KEY $file ${PROXY_USER}@${PROXY_HOST}:${PROXY_DIR} |
Answer:
That’s because this is also considered a parse error:
1 2 |
"foo"\pscp.exe |
Whereas this parses correctly as you have found:
1 2 |
"$PUTTY_PATH\pscp.exe" |
That resolves to a valid string but as you have already noticed, a string doesn’t execute. You have to use the call operator &
to invoke the command that is named by the string that follows.