posix alternative for which
This commit is contained in:
parent
03322bd398
commit
b428d17f20
52
dhl.sh
52
dhl.sh
|
@ -7,7 +7,7 @@ tn2="dhl-cp1252-rn.csv"
|
|||
|
||||
assert_tools () {
|
||||
while test $# -gt 0; do
|
||||
which $1 >/dev/null 2>/dev/null || {
|
||||
command "$1" >/dev/null 2>/dev/null || {
|
||||
echo "tool missing: "$1
|
||||
exit 2
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ teststringcrop () {
|
|||
testcmp "string" "stringcrop" "string too long" "6"
|
||||
}
|
||||
|
||||
# convert country to countrycode as in ISO3
|
||||
# convert country to countrycode as in ISO3, see https://unstats.un.org/unsd/tradekb/Knowledgebase/Country-Code
|
||||
iso3countrycode () {
|
||||
if test "$#" -eq 0 ; then
|
||||
echo "argument missing. ($0)"
|
||||
|
@ -107,6 +107,27 @@ iso3countrycode () {
|
|||
Österreich|Austria|Autriche) echo "AUT";;
|
||||
Schweiz|Switzerland|Suisse) echo "CHE";;
|
||||
Ungarn|Hungaria) echo "HUN";;
|
||||
#
|
||||
Tschechien|Czechia|Tchéquie|Česko) echo "CZE";;
|
||||
Polen|Poland|Pologne|Polska) echo "POL";;
|
||||
Weißrussland|Belarus|Biélorussie|Беларусь) echo "BLR";;
|
||||
Russland|Russia|Russie|Россия) echo "RUS";;
|
||||
Slowakei|Slovakia|Slovaquie|Slovensko) echo "SVK";;
|
||||
Italien|Italy|Italie|Italia) echo "ITA";;
|
||||
Italien|Italy|Italie|Italia) echo "ITA";;
|
||||
Norwegen|Norway|Norvège|Norge|Noreg|Norga) echo "NOR";;
|
||||
Schweden|Sweden|Suède|Sverige) echo "SWE";;
|
||||
Dänemarl|Denmark|Danemark|Danmark) echo "DNK";;
|
||||
Island|Iceland|Islande|Ísland) echo "ISL";;
|
||||
Finnland|Finland|Finlande|Suomi|Finland) echo "FIN";;
|
||||
Spanien|Spain|Espagne|España) echo "ESP";;
|
||||
Estland|Estonia|Estonie|Eesti) echo "EST";;
|
||||
Litauen|Lithuania|Lituanie|Lietuva) echo "LTU";;
|
||||
Lettland|Latvia|Lettonie|Latvija) echo "LVA";;
|
||||
Irland|Ireland|Irlande|Éire) echo "IRL";;
|
||||
Indien|India|Inde|Bharat) echo "IND";;
|
||||
China|China|Chine|中国|Zhōngguó) echo "CHN";;
|
||||
Japan|Japan|Japon|Nippon|Nihon) echo "JPN";;
|
||||
*) echo "unknown country: $1";exit 1;;
|
||||
esac
|
||||
fi
|
||||
|
@ -122,6 +143,28 @@ testiso3 () {
|
|||
testcmp "AUT" "iso3countrycode" "Österreich" "Austria" "Autriche"
|
||||
testcmp "HUN" "iso3countrycode" "Ungarn" "Hungaria"
|
||||
testcmp "CHE" "iso3countrycode" "Schweiz" "Switzerland" "Suisse"
|
||||
# and coving some more
|
||||
testcmp "CZE" "iso3countrycode" "Tschechien" "Czechia" "Tchéquie" "Česko"
|
||||
testcmp "POL" "iso3countrycode" "Polen" "Poland" "Pologne" "Polska"
|
||||
testcmp "BLR" "iso3countrycode" "Weißrussland" "Belarus" "Biélorussie" "Беларусь"
|
||||
testcmp "RUS" "iso3countrycode" "Russland" "Russia" "Russie" "Россия"
|
||||
testcmp "SVK" "iso3countrycode" "Slowakei" "Slovakia" "Slovaquie" "Slovensko"
|
||||
testcmp "ITA" "iso3countrycode" "Italien" "Italy" "Italie" "Italia"
|
||||
testcmp "ITA" "iso3countrycode" "Italien" "Italy" "Italie" "Italia"
|
||||
testcmp "NOR" "iso3countrycode" "Norwegen" "Norway" "Norvège" "Norge" "Noreg" "Norga"
|
||||
testcmp "SWE" "iso3countrycode" "Schweden" "Sweden" "Suède" "Sverige"
|
||||
testcmp "DNK" "iso3countrycode" "Dänemarl" "Denmark" "Danemark" "Danmark"
|
||||
testcmp "ISL" "iso3countrycode" "Island" "Iceland" "Islande" "Ísland"
|
||||
testcmp "FIN" "iso3countrycode" "Finnland" "Finland" "Finlande" "Suomi" "Finland"
|
||||
testcmp "ESP" "iso3countrycode" "Spanien" "Spain" "Espagne" "España"
|
||||
testcmp "EST" "iso3countrycode" "Estland" "Estonia" "Estonie" "Eesti"
|
||||
testcmp "LTU" "iso3countrycode" "Litauen" "Lithuania" "Lituanie" "Lietuva"
|
||||
testcmp "LVA" "iso3countrycode" "Lettland" "Latvia" "Lettonie" "Latvija"
|
||||
testcmp "IRL" "iso3countrycode" "Irland" "Ireland" "Irlande" "Éire"
|
||||
testcmp "IND" "iso3countrycode" "Indien" "India" "Inde" "Bharat"
|
||||
testcmp "CHN" "iso3countrycode" "China" "China" "Chine" "中国" "Zhōngguó"
|
||||
testcmp "JPN" "iso3countrycode" "Japan" "Japan" "Japon" "Nippon" "Nihon"
|
||||
|
||||
testcmp "" "iso3countrycode" "Simbabwe" # should fail
|
||||
}
|
||||
|
||||
|
@ -149,7 +192,7 @@ getauth () {
|
|||
user=$(cat ds.conf|grep -i "^user="|cut -d= -f2) #
|
||||
pass=$(cat ds.conf|grep -i "^pass="|cut -d= -f2) #
|
||||
} || {
|
||||
which pass 2>/dev/null && {
|
||||
command pass 2>/dev/null && {
|
||||
passfile="$(cat ds.conf|grep -i "^passfile="|cut -d= -f2)" # ccc/doku-htaccess
|
||||
passstore="$(cat ds.conf|grep -i "^passstore="|cut -d= -f2)" # ~/.password-store/
|
||||
test -f ${passstore}${passfile} || { >&2 echo "path for password manager does not match: "${passfile}; exit 1; }
|
||||
|
@ -193,10 +236,11 @@ convcsv () {
|
|||
if test $# -eq 0 ; then >&2 echo "argument missing."; exit 1; fi
|
||||
# doc for headless conversion options https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
|
||||
if="${1}"
|
||||
format=$(file ${if}|cut -d' ' -f2)
|
||||
format=$(file ${if}|cut -d':' -f2-|cut -d' ' -f2)
|
||||
if test "$format" != "UTF-8" ; then >&2 echo "source file encoding not matching the expected UTF-8."; fi
|
||||
of=$(echo "${if}"|rev|cut -d. -f2-|rev)".ods"
|
||||
if test -e $of ; then >&2 echo "output file already exists."; exit 2; fi
|
||||
#~ iconv -o "$of" -f $format -t cp1252//TRANSLIT "$if"
|
||||
#~ iconv -o "$of" -f $format -t WINDOWS-1252 "$if"
|
||||
# to take care of more options in csv at the same time, convert to ods and back to csv
|
||||
libreoffice --headless --convert-to ods --infilter=CSV:59,34,76,1 "${if}" && {
|
||||
|
|
Loading…
Reference in New Issue