Closed filmil closed 6 years ago
Looks like argbash produces DOS file endings for some reason.
Here's the result of hexdump -C ./test_argbash.sh
, clipped at first 4 rows.
Note the bytes 0d 0a
after #!/bin/bash
.
00000000 23 21 2f 62 69 6e 2f 62 61 73 68 0d 0a 23 0d 0a |#!/bin/bash..#..|
00000010 23 20 54 68 69 73 20 69 73 20 61 20 72 61 74 68 |# This is a rath|
00000020 65 72 20 6d 69 6e 69 6d 61 6c 20 65 78 61 6d 70 |er minimal examp|
00000030 6c 65 20 41 72 67 62 61 73 68 20 70 6f 74 65 6e |le Argbash poten|
However, the input file has UNIX file endings. For hexdump -C ./test.sh
, note that there's only 0a
following #!/bin/bash
.
00000000 23 21 2f 62 69 6e 2f 62 61 73 68 0a 23 0a 23 20 |#!/bin/bash.#.# |
00000010 54 68 69 73 20 69 73 20 61 20 72 61 74 68 65 72 |This is a rather|
00000020 20 6d 69 6e 69 6d 61 6c 20 65 78 61 6d 70 6c 65 | minimal example|
Indeed, as a workaround:
dos2unix < test_argbash.sh > test_argbash2.sh
chmod +x test_argbash2.sh
./test_argbash2.sh
gives the expected output:
The general script's help msg
Usage: ./test_argbash2.sh [-o|--option <arg>] [--(no-)print] [-h|--help] <positional-arg>
<positional-arg>: positional argument help msg
-o,--option: optional argument help msg (no default)
--print,--no-print: boolean optional argument help msg (off by default)
-h,--help: Prints help
FATAL ERROR: Not enough positional arguments - we require exactly 1 (namely: 'positional-arg'), but got only 0.
While this is easy to work around, I'd argue that argbash should probably work out of the box with the correct line endings. What do you think?
Thank you for your elaborate report, I have tried myself and I have discovered this:
argbash
with the -o/--oputput
option.argbash
, so it should be documented, and maybe there should be a check for -o|--output
presence in the container entrypoint script.
Can you confirm this observation?Note that -o <path>
is problematic if your output is outside of /work
in a container, since the container currently has limited view of the host's filesystem (as it should be).
I think it could work by taking realpath
of the -o parameter and then mounting that under a known path in a container. Not sure if I'll have the time to send you a pull request, though.
I have improved the documentation and added some code to produce warnings to the entrypoint in the current master. I will be happy about any pull request, but I think that I can close the issue.
When using argbash's docker image to convert the file:
using the script:
to convert:
one gets a file that fails to execute with bizarre errors:
Looking into this a bit, and redirecting like so:
one gets something clearer: