Problem with input parameters

Hi

I wrote a script which lists the content of a given directory.
I have just one problem. If you give 2 or more parameters, then it gives a strange error. After that error, it gives also an error from my script, but normally it shouldn't give that error.

Here's my script.You can test it.

#!/bin/bash

EDITOR=vim
PASSWD=/etc/passwd
RED='\033[0;41;30m'
STD='\033[0;0;39m'

pause(){
  read -p "Press [Enter] key to continue..." fackEnterKey
}
 

one(){
    echo "Give in a directory name:"
    read name
    if [ ! $# -gt 0 ]; then
        if [ -d $name ]; then
            echo "Ok. Here's the content of the given directory:"
            echo
            ls -l -- $name
            exit 0
        else
            echo "Directory name doesn't exist or isn't a directory."
            exit 1
        fi
    
    else
        echo "No or more than one param."
        exit 2
    fi
            pause
    }

show_menus() {
    clear  
    echo "~~~~~~~~~~~~~~~~~~~~~"    
    echo "      MAIN - MENU       "
    echo "~~~~~~~~~~~~~~~~~~~~~"
    echo "1. List content of a directory by given param"
    echo "2. Exit"
}

# read input from the keyboard and take a action
# invoke the one() when the user select 1 from the menu option.
# Exit when user the user select 2 form the menu option.
read_options(){
    local choice
    read -p "Enter choice [ 1 - 2] " choice
    case $choice in
        1)     one ;;
        2)     exit 0;;
        *)     echo -e "${RED}Error...${STD}" && sleep 1
    esac
}

# ----------------------------------------------
# Ignore CTRL+C, CTRL+Z and quit singles
# ----------------------------------------------
trap '' SIGINT SIGQUIT SIGTSTP

# -----------------------------------
# List menu while true
# ------------------------------------
while true
do 
    clear 
    show_menus
    read_options
done

Hi,

I don't understand. The script gives a menu with 2 options. Second one exits and first one ask for a directory and lists its contents, can you be more specific to find the point of failure??

Regards,
Birei

Except the trap statement that i must comment, i don't see any problem like that when i use your script.

Hi,

name should be read as an array:

$ read -ea name
my\ file myOther File
$ printf '%s\n' "${name[@]}"
my file
myOther
File
[ -n "$name" ] && echo "$name" || echo KO
my file

and you should use more quotes:

 [ -d "$name" ]
...
ls -l -- "$name"