When I run these lines in my terminal on macOS I get the correct result
hex=$(echo -n 'betty' | xxd -p) echo $hex 6265747479 but when I run them in a bash script I get something completely different
sh myscript.sh 62657474790a It's like its put a carriage return on the end for some reason. WHY?
cat myscript.sh; sh myscript.shshas a shell, and we don't know where sh is linked to on your machine. If both are bash shells, they might be different versions (do aprint $BASH_VERSIONin both variants), which implement theechoin a different way.echo -n 'betty'would produce that output, which appears to bebettyfollowed by a newline. I'd expect eitherbettywithout a newline, or-n bettywith a newline. What exactly doessh -c 'echo -n betty'print, compared toecho -n betty? What doesls -l /bin/shsay?sh -c 'echo -n betty'gives me-n bettyecho -n bettygives mebettywith the next prompt on the same line as bettyls -l /bin/sh=>-r-xr-xr-x 1 root wheel 630464 29 Apr 10:31 /bin/sh