Sponsored Content
Top Forums Shell Programming and Scripting Perl : accept multiple user entered command line arguemnts Post 302852959 by Smiling Dragon on Thursday 12th of September 2013 09:36:19 PM
Old 09-12-2013
Set a flag at the start, use a while loop based on it, unset it once you are happy all is well.
Code:
my $redo=1;
while ($redo) {

  <ask your questions>

  print "Are these statements correct y or n ?\n";
  my $ans=<>;
  if ($ans =~ m/n/i) {
    print "No\n"; 
  } else {
    $redo=0;
  }
}

You don't need the 'm' in 'm/n/i' by the way, because you are doing a readline (<>) you're parsing a single line by definition.
This User Gave Thanks to Smiling Dragon For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

getting rid of $ when entered at the command line

Hi everyone, Can someone possibly help me with this problem I am having please. I wrote a Korn shell script to manipulate currency amounts in a way that a person could use this script to determine the minimum number of coins required to make a certain amount. for example when entered on the... (2 Replies)
Discussion started by: bashirpopal
2 Replies

2. Solaris

Removing user from multiple groups via command line

Want to know if any, a command line parameter(s) of removing a user from multiple groups without using any ineractive application? (1 Reply)
Discussion started by: jquizon62
1 Replies

3. UNIX for Dummies Questions & Answers

Append 0 for single digit entered from command line

I have a script like this-- #!/bin/ksh echo "To pad a 0 before digits from 1-9" for i in $* do echo $i | sed 's//'0'/g' done I run this script as ksh name 1 2 23 34 The output should be 01 02 23 34 Help me in modifying this script. Thanks Namish (2 Replies)
Discussion started by: namishtiwari
2 Replies

4. Shell Programming and Scripting

SQL PLUS Command 'ACCEPT' is not waiting for user input with sh shell script

Dear All, The sqlplus 'Accept' command is not waiting for user input when I include the command within a shell script. Note: The 'Accept' command is working fine if I execute it in a SQLPLUS Prompt. Please fins the below sample script which i tried. SCRIPT: -------- #!... (4 Replies)
Discussion started by: little_wonder
4 Replies

5. Programming

How to accept multiple lines input from User in C?

Hi I want to accept multiple lines input with spaces from User and i have a working code like this. char sRes; char sReq; printf("Please enter request:"); scanf("%",sReq); /* Accept the input from user */ printf("\nPlease enter response:"); scanf("%",sRes); but the... (4 Replies)
Discussion started by: AAKhan
4 Replies

6. Shell Programming and Scripting

How to loop through array who's name is entered in command line?

Say I have a ksh program called test.ksh which has several defined arrays inside it such as array1,array2,array3...These arrays contain strings. I also have a method in the program: for x in $1 do ....(#do something) done So, when the user enteres: ./test.ksh array1, I want to... (3 Replies)
Discussion started by: mrskittles99
3 Replies

7. Shell Programming and Scripting

How to accept command line argument as character or text if number is entered?

Hello Does the unix korn shell provide a function to convert number entered in command line argument to text or Character so that in next step i will convert Chr to Hex (6 Replies)
Discussion started by: aadityapatel198
6 Replies

8. Programming

Make a file accept only two arguments from the command line

DELETED (2 Replies)
Discussion started by: ProgMan2015
2 Replies

9. Homework & Coursework Questions

Make a file accept only two arguments from the command line

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) The script is executed in the Korn shell. 2) Name the shell script file is asg6s. 3) The asg6s file is... (7 Replies)
Discussion started by: ProgMan2015
7 Replies

10. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies
ReadPassword(3pm)					User Contributed Perl Documentation					 ReadPassword(3pm)

NAME
Term::ReadPassword - Asking the user for a password SYNOPSIS
use Term::ReadPassword; while(1) { my $password = read_password('password: '); redo unless defined $password; if ($password eq 'flubber') { print "Access granted. "; last; } else { print "Access denied. "; redo; } } DESCRIPTION
This module lets you ask the user for a password in the traditional way, from the keyboard, without echoing. This is not intended for use over the web; user authentication over the web is another matter entirely. Also, this module should generally be used in conjunction with Perl's crypt() function, sold separately. The read_password function prompts for input, reads a line of text from the keyboard, then returns that line to the caller. The line of text doesn't include the newline character, so there's no need to use chomp. While the user is entering the text, a few special characters are processed. The character delete (or the character backspace) will back up one character, removing the last character in the input buffer (if any). The character CR (or the character LF) will signal the end of input, causing the accumulated input buffer to be returned. Control-U will empty the input buffer. And, optionally, the character Control-C may be used to terminate the input operation. (See details below.) All other characters, even ones which would normally have special pur- poses, will be added to the input buffer. It is not recommended, though, that you use the as-yet-unspecified control characters in your passwords, as those characters may become meaningful in a future version of this module. Applications which allow the user to set their own passwords may wish to enforce this rule, perhaps with code something like this: { # Naked block for scoping and redo my $new_pw = read_password("Enter your new password: "); if ($new_pw =~ /([^x20-x7E])/) { my $bad = unpack "H*", $1; print "Your password may not contain the "; print "character with hex code $bad. "; redo; } elsif (length($new_pw) < 5) { print "Your password must be longer than that! "; redo; } elsif ($new_pw ne read_password("Enter it again: ")) { print "Passwords don't match. "; redo; } else { &change_password($new_pw); print "Your password is now changed. "; } } The second parameter to read_password is the optional "idle_timeout" value. If it is a non-zero number and there is no keyboard input for that many seconds, the input operation will terminate. Notice that this is not an overall time limit, as the timer is restarted with each new character. The third parameter will optionally allow the input operation to be terminated by the user with Control-C. If this is not supplied, or is false, a typed Control-C will be entered into the input buffer just as any other character. In that case, there is no way from the keyboard to terminate the program while it is waiting for input. (That is to say, the normal ability to generate signals from the keyboard is sus- pended during the call to read_password.) If the input operation terminates early (either because the idle_timeout was exceeded, or because a Control-C was enabled and typed), the return value will be "undef". In either case, there is no way provided to discover what (if anything) was typed before the early termina- tion, or why the input operation was terminated. So as to discourage users from typing their passwords anywhere except at the prompt, any input which has been "typed ahead" before the prompt appears will be discarded. And whether the input operation terminates normally or not, a newline character will be printed, so that the cursor will not remain on the line after the prompt. BUGS
Windows users will want Term::ReadPassword::Win32. This module has a poorly-designed interface, and should be thoroughly rethought and probably re-united with the Windows version. Users who wish to see password characters echoed as stars may set $Term::ReadPassword::USE_STARS to a true value. The bugs are that some terminals may not erase stars when the user corrects an error, and that using stars leaks information to shoulder-surfers. SECURITY
You would think that a module dealing with passwords would be full of security features. You'd think that, but you'd be wrong. For example, perl provides no way to erase a piece of data from memory. (It's easy to erase it so that it can't be accessed from perl, but that's not the same thing as expunging it from the actual memory.) If you've entered a password, even if the variable that contained that password has been erased, it may be possible for someone to find that password, in plaintext, in a core dump. And that's just one potential security hole. In short, if serious security is an issue, don't use this module. LICENSE
This program is free software; you may redistribute it, modify it, or both, under the same terms as Perl itself. AUTHOR
Tom Phoenix <rootbeer@redcat.com>. Copyright (C) 2007 Tom Phoenix. SEE ALSO
Term::ReadLine, "crypt" in perlfunc, and your system's manpages for the low-level I/O operations used here. perl v5.8.8 2008-03-12 ReadPassword(3pm)
All times are GMT -4. The time now is 07:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy