Command line inputs validation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command line inputs validation
# 1  
Old 05-29-2006
Command line inputs validation

Hi,
I have a script called read.sh that takes a file as input. Now I want to make that script take the file as input with a -f option preceding the filename. How can I do this validation. How can I find whether the given option is -f or not inside the script.

Thanks in advance
# 2  
Old 05-29-2006
Use getopts
# 3  
Old 05-29-2006
one more is direct argument validation....

as ,

Code:
if [ $1 = "-f" ]
then
echo "yes"
else
echo "no"
fi

something like that !!!...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script to accept Multi line inputs

Hi there, I'm trying to create a script that will accept multiple inputs by copying and pasting the strings from a notepad, hit Enter key and output the string to a text file.I'm thinking of using the read command however it will just simply get the first line. Apologies but got no idea how... (7 Replies)
Discussion started by: norbie.lopez
7 Replies

2. Shell Programming and Scripting

[Solved] How to refer more than 9 command line inputs for a scripts in korn shell?

Hi all, I have a script which should take more than 9 command line inputs while running. Likescript.sh a s d f g h j j k l o p i u y t r e w Now in the script if I have to access one of the input which is at position after 9, in this case say 'p' then how can I do that? echo $12 will not work... (15 Replies)
Discussion started by: pat_pramod
15 Replies

3. UNIX for Dummies Questions & Answers

How to send keyboard inputs toa UNIX command executed from a shell script?

I have a unix command that prompts for 'y'. How do I run this from my shell script? (4 Replies)
Discussion started by: Sree10
4 Replies

4. Shell Programming and Scripting

Problem in sending inputs to format command using expect

Hi , I am not able figure out how to use expect tool to send input to this prompt of format Searching for disks...done selecting c0t3d0 FORMAT MENU: disk - select a disk type - select (define) a disk type partition - select (define) a partition... (3 Replies)
Discussion started by: chidori
3 Replies

5. UNIX for Dummies Questions & Answers

cron command validation

In cron tab, while scheduling any commands to be run in particular time, is there any level of validation being performed to identify whether the command to be executed is perfectly valid. But AFAIK, it's not being reported even if you schedule a non existing command .say tea abc, Where tea ia a... (3 Replies)
Discussion started by: pandeesh
3 Replies

6. Shell Programming and Scripting

edit a line for getting inputs

Hello Everybody, I have a file with data like this 8z:1 15y:0 7x:0 12w:1 ... ... I would like read each line through a loop and will needing to get the input from each line like this For 8z:1; a=8,b=1 15y:0; a=15,b=0 7x:0; a=7,b=0 Please let me know of a way to... (5 Replies)
Discussion started by: leo.maveriick
5 Replies

7. Shell Programming and Scripting

Command line user input validation

Hi guys, I have a piece of snippet below which asks the user to input some numbers if isDatasubEnabled && isReconEnabled; then echo "1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit" elif isDatasubEnabled &&... (4 Replies)
Discussion started by: pyscho
4 Replies

8. Shell Programming and Scripting

AWK - Line length validation

Hi, I have requirement where record length is stored in an variable RECORD_LENGTH Code goes as follows RECORD_LENGTH=537 the above is arrived from #RECORD_LENGTH=`awk -F"=" '{$sum+=$2} END{print $sum}' DBP_Claims_CFG.ini` awk ' { if (length() == '$RECORD_LENGTH') print FNR, $0... (4 Replies)
Discussion started by: ainuddin
4 Replies

9. Shell Programming and Scripting

AWK - Line length validation

I am attempting to use awk to validate the length of each line in a fixed-width raw data file prior to reading in the data. I am happy with.... {if (length() == 403) print > "valid.file"; else print > " invalid.file" } ...to separate out the valid length lines from invalid length... (3 Replies)
Discussion started by: en7smb
3 Replies

10. Shell Programming and Scripting

Vaildation of command line inputs

Hi, I want to do the following validations in my script when my script gets 2 parameters as command line inputs. My script expects 2 inputs : a -f option and a filename If a filename is given as input without the -f option then I have to exit. If only -f option is given and no filename is... (6 Replies)
Discussion started by: sendhilmani123
6 Replies
Login or Register to Ask a Question