Script fails on return code greater than 1, but not on 1

Advertisement

andreas
Guest

Script fails on return code greater than 1, but not on 1

Hello Martin,
A script returning with code 1 does is not processed the same way as a script returning a code greater than 1.

On linux, create two scripts:
script rc1:
#!/bin/sh
exit 1
script rc2:
#!/bin/sh
exit 2
then do chmod a+x rc*
and run remotely:
WinSCP /command "open sftp://<uid>:<psw>@<machine>" "option echo on"
"call echo hello" \
"call ./rc1" \
"call echo bye" \
"exit"
output:
...
hello
call ./rc1
call echo bye
bye
exit
and then run 2nd command:
WinSCP /command "open sftp://<uid>:<psw>@<machine>" "option echo on"
"call echo hello" \
"call ./rc2" \
"call echo bye" \
"exit"
output:
...
hello
call ./rc2
Command './rc2'
failed with return code 2 and error message
.

Why isn't return code 1 considered an error?

re. https://shapeshed.com/unix-exit-codes/
What exit code should I use?
...
1 - Catchall for general errors
2 - Misuse of shell builtins (according to Bash documentation)
126 - Command invoked cannot execute
...
Thanks,
Andre

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
29,561
Location:
Prague, Czechia

Re: Script fails on return code greater than 1, but not on 1

I do not really remember the historical reasons for this anymore.
It may be related to ls command returning 1 as a warning.

Anyway, the next version of WinSCP will optionally allow treating 1 as an error, when executing user shell commands on a server:
https://winscp.net/tracker/1694

I can send you a development version for testing, if you contact me on my email address.

You will find my address (if you log in) in my forum profile.

Reply with quote

Advertisement

You can post new topics in this forum