Sponsored Content
Top Forums Shell Programming and Scripting Bash Script verify user input is not empty and is equal to a value Post 302390079 by fubaya on Wednesday 27th of January 2010 12:03:07 AM
Old 01-27-2010
I'm not great with tests so I don't know if this is the best way, but I had the same problem recently and finally got this to work best:
Code:
while  [[ $choice != '1' ]] && [[ $choice != '2' ]] && [[ $choice != '3' ]]; do

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script error with when input is empty

Hi, I created the following shell script to lookup multiple name servers for a domain. #!/bin/bash echo -n "Enter the domain name and press : " read domain result1=`dig +short $domain @4.2.2.1` revresult1=`host $result1 | cut -f5 -d " "` echo "test1" result2=`dig +short... (3 Replies)
Discussion started by: mohitmoudgil
3 Replies

2. UNIX for Dummies Questions & Answers

BASH validate user input

Hey, im trying to validate a user input and need some help. The input needs to be just a single letter. Im using a case to so this eg: read answer case $answer in *) echo "OK" ;; *) echo "This is a number" read answer ;; *) echo... (2 Replies)
Discussion started by: 602chrislys
2 Replies

3. Shell Programming and Scripting

BASH Varible nesting and user input

Well, I think I've managed to take two different issues and conglomerate them into and embarrasing mess. #!/bin/bash # Set some variables dir1=/path/that/isnt/variable/$variabledir/dir/ dir2=/path/that/isnt/variable/$variabledir/important/"$variabledir"-subdirectory/path/ echo "Gimme... (7 Replies)
Discussion started by: karlp
7 Replies

4. Shell Programming and Scripting

Bash user input

Hi all, I currently have a script which uses read -p for user interaction. e.g. read -p "New user? " user Is it possible to have it so if the user enters nothing and just presses return it can resort to a specified value instead? Thanks! :) (5 Replies)
Discussion started by: JayC89
5 Replies

5. UNIX for Advanced & Expert Users

Verify file was sftp'd via bash script

Hello Experts, I have a script that that transfers a file (via sftp) and it works fine but we ran into a snag where the target server asked for the ssh key and the script didn't know what to do. I want to add some logic to this script that at least sends an email that it didn't complete as... (4 Replies)
Discussion started by: Tiberius777
4 Replies

6. Shell Programming and Scripting

Help with Bash user input

I am starting to learn how to use bash and I would like the script to do the following: Asks the user for his/her name Asks the user for one number Asks the user for another number Then it adds the two numbers, Also multiply the two numbers I have the part where you get the name, and I... (3 Replies)
Discussion started by: boyboy1212
3 Replies

7. Shell Programming and Scripting

[bash] how is proper way to validate user input

hi all, i have a script that need user input provide all variables that needed to complete a job. this is my current script: echo "type file source and it full path :" read INPUTFILE if || ; then echo "ERROR: you didn't enter a file source or file source is not... (2 Replies)
Discussion started by: makan
2 Replies

8. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

9. Homework & Coursework Questions

Bash Script for Dice Game; Issue with if...else loop to verify user guess is within range

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: I have written a script for a dice game that: (1) tells user that each of the 2 die are 6 sided (Spots=6); (2)... (3 Replies)
Discussion started by: LaurenRose
3 Replies

10. Shell Programming and Scripting

Bash to verify each line in input for specific pattern

In the bash below the out put of a process is written to input. What I am trying to do is read each line in the input and verify/check it for specific text (there are always 6 lines for each file and the specific text for each line is in the description). There will always be 6 lines in each... (5 Replies)
Discussion started by: cmccabe
5 Replies
ppd_find_choice(3)					     Library Functions Manual						ppd_find_choice(3)

NAME
ppd_find_choice, ppd_find_marked_choice, ppd_find_option_by_keyword - set of functions for returning pointers to choices from PPD files. SYNOPSIS
#include <ppd.h> PpdChoice *ppd_find_choice (PpdOption *o, const char *choice); PpdChoice *ppd_find_marked_choice (PpdFile *ppd, const char *keyword); PpdOption *ppd_find_option_by_keyword (PpdFile *ppd, const char *keyword); DESCRIPTION
These three functions allow the programmer access options and choices within a PPD file. PpdChoice *ppd_find_choice (PpdOption *o, const char *choice); This function accepts two parameters. The first is a pointer to a PPD option structure and the second is the name of the choice to locate. PpdChoice *ppd_find_marked_choice (PpdFile *ppd, const char *keyword); This function accepts a valid PpdFile pointer (see ppd_file_new(3)) and a keyword or option name to locate in the PPD file. PpdOption *ppd_find_option_by_keyword (PpdFile *ppd, const char *keyword); This function accepts two parameters which are identical to those used when invoking the ppd_find_marked_choice() function. However, the ppd_find_option_by_keyword() function does not mark the designated option as being selected. RETURN VALUE
ppd_find_choice() Return a pointer to an option choice; NULL in the case of a failure ppd_find_marked_choice() Return the marked choice for the specified option; NULL in the case of a failure ppd_find_option_by_keyword() Return a pointer to the specified option; NULL in the case of a failure SEE ALSO
ppd_file_new(3), ppd_emit_to_file(3), ppd_file_free(3), ppd_get_num_conflicts(3), ppd_check_option_is_marked(3), ppd_get_page_length(3) AUTHOR
This man page was written by Gerald Carter <gcarter@valinux.com>. It was updated by Mark Fasheh <mfasheh@valinux.com> to reflect changes in libppd 0.5 Some of the code for these functions was originally part of the Common UNIX Printing System (CUPS). ppd_find_choice(3)
All times are GMT -4. The time now is 01:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy