From faa25471d9ef2a4cb50f71eb66b0b32bed4518d8 Mon Sep 17 00:00:00 2001 From: mfhepp Date: Sun, 28 Jan 2024 17:04:55 +0100 Subject: [PATCH] POSIX-compliant conditions for better portability --- cdf.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cdf.sh b/cdf.sh index bf8e529..3608555 100644 --- a/cdf.sh +++ b/cdf.sh @@ -44,12 +44,13 @@ _validate_basename() { local sanitized # Remove leading and trailing whitespace and replace forbidden characters sanitized=$(echo "$input" | xargs | sed 's/[^a-zA-Z0-9_-]/_/g') - if [[ "$sanitized" != "$input" ]]; then + if [ "$sanitized" != "$input" ]; then # echo "ERROR: Argument contains invalid characters (consider $sanitized instead)" return 1 fi } + _cdf_list() { # List all available shortcuts printf "Usage: cdf NAME\n\n" @@ -81,7 +82,8 @@ addfav() { else # Check that the current directory is neither the place for the symlinks nor a subdirectory therof CURRENT_DIR=$(pwd) - if [[ "$CURRENT_DIR" = "$CDFPATH" || "$CURRENT_DIR" == "$CDFPATH"/* ]]; then + # Bash-only version: if [[ "$CURRENT_DIR" = "$CDFPATH" || "$CURRENT_DIR" == "$CDFPATH"/* ]]; then + if [ "$CURRENT_DIR" = "$CDFPATH" ] || [ "${CURRENT_DIR##$CDFPATH/}" != "$CURRENT_DIR" ]; then printf "ERROR: You cannot create shortcuts to the shortcuts folder or its subdirectories\n" return 1 # Check if we are INSIDE a symbolic link