Sponsored Content
Top Forums Shell Programming and Scripting Problem with input parameters Post 302524110 by hss on Saturday 21st of May 2011 03:13:47 PM
Old 05-21-2011
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.

Code:
#!/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


Last edited by hss; 05-22-2011 at 08:13 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Accept input parameters

Dear All, I got a table creation file in a standard format. I need to accept parameters from the user & then based on the input change the data in the file. For. eg. i will accept the database name, dbspace name & user name from the user and accordingly change the same in the table creation... (2 Replies)
Discussion started by: lloydnwo
2 Replies

2. Shell Programming and Scripting

Input parameters

I have a script which take 3 input parameters 1st - a date (i.e. current date) 2nd - type (i.e. A) 3rd - limit (i.e. 40) normally the date parameter would be current date, so I thought I could do this calculate.sh $(date +%Y-%m-%d) A 40 however, it seems like it can't be done,... (3 Replies)
Discussion started by: mpang_
3 Replies

3. Shell Programming and Scripting

input parameters pls help!

Hi i am a newbie who is trying to input parameters into this script, but not sure where to start. The parameters that need to be input are the baseline label "abc.0111.BL " mantioned bellow, and database string "abc/abcp@db2 @counter.sql " Environment: Windows XP Running script: Cygwin 3.2 ... (2 Replies)
Discussion started by: yarik20
2 Replies

4. Shell Programming and Scripting

Validating Input parameters

Hi All, I have tried to use ckdate (sun) command in script. It checks the input parameter which should be in 'YYYYMMDD format. date=$( echo $1 | ckdate -f "%Y%m%d") | true if ] then print " success" else print "no success" fi But in whatever format i pass the parameter,... (3 Replies)
Discussion started by: Amit.Sagpariya
3 Replies

5. Shell Programming and Scripting

Verify input parameters

I have to write a script to verify input parameters; say esr should be YES or NO other wise the script should print an error. This is what i tried in my script but I get the following error : esr="YES" if ; then print " Error should specify esr options YES/NO" else esr =$esr fi ... (2 Replies)
Discussion started by: ramky79
2 Replies

6. UNIX for Dummies Questions & Answers

Problem with Input Parameters using Shell Script

i have this basic code that accepts for two input one for the source file and the other is for the target directory. basically it is a simple copy command. the problem is at the end of the execution the second parameter string was passed to first parameter and it displays a message like: cp:... (3 Replies)
Discussion started by: wtolentino
3 Replies

7. Shell Programming and Scripting

Problem with Input parameters

Hi, I am facing a weird problem with input parameters. Please find more details about my problem below: a) I am executing a korn shellscript with 11 input parameters from "Appworx" tool (it's a scheduling tool) and immediately displaying those 11 parameter values in unixscript and noticed... (4 Replies)
Discussion started by: npk2210
4 Replies

8. Shell Programming and Scripting

How to validate input parameters?

Hi, I wonder how I can know if the input parameters to the script are numbers or text Thanks (11 Replies)
Discussion started by: Gengis-Kahn
11 Replies

9. Shell Programming and Scripting

How can I take input parameters after the first one?

Hi, Is there a simple way to take input of parameters after the first one? As following example, if I assign others=$2, it only takes the second one, if I assign others=$@, it will include the first one. I may try to assign others="$2 $3 $4 $5 $6 $7 $8 $9", it looks very ugly and could missing... (1 Reply)
Discussion started by: hce
1 Replies

10. AIX

Input parameters

friends and I can validate whether to run the shell has input parameters m event date, I occasionally happen something like this does not work if $ 1 is null then echo has entered input parameters else echo "parameter ok" fi (2 Replies)
Discussion started by: tricampeon81
2 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 01:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy