The user Random832 wrote:
[...] create an empty tar file [...]
Disclaimer: I have not tested this script.
God bless you! You gave me ideas. I tested your script, but if someone creates a empty tar file, tar doesn't consider it a "posix tar" file. So I wrote a script that creates a "posix tar" file with something inside, and finally deletes it. I named it "gnu2posix", people can use it freely:
#!/bin/bash
set -o nounset
### // Convert a tar file, from the "gnu tar" format to the "posix tar" one (which in Windows, for example, allows seeing correctly all of the utf-8 characters of the names of the files)
NAME_PROGRAM=$(basename "$0")
alert() {
echo "$@" >&2 ;
}
alert_about_usage() {
echo "The usage of this program is: $NAME_PROGRAM FILE_TO_CONVERT RESULTING_FILE" >&2
}
if [[ $# != 2 ]]; then
alert "ERROR: the program \"$NAME_PROGRAM\" needs two arguments, but it has received: $#."
alert_about_usage
exit 1;
fi
file_to_convert="$1"
if [[ ! -f "$file_to_convert" ]]; then
error "ERROR: the program \"$NAME_PROGRAM\" can't access any file with this path: \"$file_to_convert\"."
alert_about_usage
exit 1;
fi
resulting_file="$2"
# // Create a file with something inside, in this case, the "." folder (without its contents). This way, a real "posix tar" is created
tar --format=posix -cf "$resulting_file" . --no-recursion
# // Add "$file_to_convert", finally getting a "posix tar" file
tar -Avf "$resulting_file" "$file_to_convert"
# // Just in case, delete the "." folder from the file
tar -f "$resulting_file" --delete "."
# // End of file