kbasename: versión Korn Shell de basename

This commit is contained in:
Tuxliban Torvalds 2023-05-25 03:20:12 -06:00
parent c16fcaab3e
commit 2f1364820e
1 changed files with 31 additions and 0 deletions

31
functions_korn/kbasename Normal file
View File

@ -0,0 +1,31 @@
# Versión Korn Shell de basename
function kbasename {
# Comprobar argumentos
if (($# == 0 || $# > 2 )); then
printf %s "\
Uso: ${0##*/} string [sufijo]
Ejemplos:
${0##*/} /path/foo.xyz
foo.xyz\n
${0##*/} /path/foo .xyz
foo
"
exit 1
fi
# Obtener el nombre base
BASE=${1##*/}
# Ver si se ha dado el argumento sufijo
if (($# > 1 )); then
# Mostrar nombre base sin sufijo
print ${BASE%$2}
else
# Mostrar nombre base
print $BASE
fi
}