I have a few shell scripts with UTF8-encoded characters inside and i want to be sure that they are decoded correctly regardless of the machine locale settings.
Is it possible to force the shell (bash or sh) to detect the correct script encoding? (something similar to the python or ruby encoding cookie)
The solution could be a custom shebang like:
The solution should aim to better portability, so it is not necessary to stick with bash.
EDIT: maybe i've found a possible solution using a recursive script call:
# check if current locale is UTF8-based (otherwise this script may not work correctly) locale | grep -q 'UTF-8' if [ $? -ne 0 ]; then export LC_ALL=en_GB.UTF-8 # recursive call this script with the modified environment $0 "$@" exit $? fi