user-input

bash: choose default from case when enter is pressed in a “select” prompt

你。 提交于 2019-12-04 02:04:00
I'm prompting questions in a bash script like this: optionsAudits=("Yep" "Nope") echo "Include audits?" select opt in "${optionsAudits[@]}"; do case $REPLY in 1) includeAudits=true; break ;; 2) includeAudits=false; break ;; "\n") echo "You pressed enter"; break ;; # <--- doesn't work *) echo "What's that?"; exit;; esac done How can I select a default option when enter is pressed? The "\n" case does not catch the enter key. mklement0 To complement Aserre's helpful answer , which explains the problem with your code and offers an effective workaround, with background information and a generic,

Using user input to create a new object [JAVA]

浪子不回头ぞ 提交于 2019-12-04 01:52:29
问题 Hi I am trying to create a program to create a new object whenever the user inputs a new information for a certain object. Currently I have this. import java.util.Scanner; public class Main { public static void main (String args[]) { String input; Scanner scanner = new Scanner(System.in); do { System.out.println("Computer Menu"); System.out.println("1. Add a new Desktop Information"); System.out.println("2. Add a new Laptop Information"); System.out.println("3. Display all Computer

Turn a User Input String to Upper Case Java

不羁的心 提交于 2019-12-04 01:16:33
问题 This may seem like a silly question, but after going through pages of google, i havnt been able to find the answer i want. s1.setName(JOptionPane.showInputDialog("Enter Name: "); For the above piece fo code, how would i format the data the user entered to be all capitals? Any help here would be appreciated. 回答1: The String class has a toUpperCase() method on it. JOptionPane.showInputDialog(..) returns a String, so you can use: JOptionPane.showInputDialog("Enter name: ").toUpperCase(); 回答2:

Is it safe to use user's RegEx?

限于喜欢 提交于 2019-12-04 00:49:13
I want to add a feature to my website to let users search the texts with RegEx . But, is it safe to let the users do something like that ? preg_match('/' . $user_input_regex . '/', $subject); There is a possible attack on this code called a ReDoS attack (Regular expression Denial of Service). The Regular expression Denial of Service (ReDoS) is a Denial of Service attack, that exploits the fact that most Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size). An attacker can then cause a program using a Regular

Force user input in verbatim mode?

随声附和 提交于 2019-12-03 21:47:54
I'm trying to any read user input keys in verbatim from Bash script, and then dump it into hex. That is: read input printf "%b" "$input" | xxd -p If user press 2 keys a BACKSPACE , I would hope the output to be 617f , not empty. How can I achieve that? This should work #!/bin/bash while true;do stty_state=$(stty -g) #Save stty to reset to default stty raw isig -echo #Set to raw and isig so nothing is interpretted and turn echo off so nothing is printed to screen. keypress=$(dd count=1 2>/dev/null) #Capture one character at a time #Redirect "errors" (from dd) output to dump keycode=$(printf "%s

How do I display a website with html-forms locally using python and collect the user input?

淺唱寂寞╮ 提交于 2019-12-03 21:38:22
问题 I am a behavorial scientist and usually collect data by letting participants do some tasks on a computer and record their responses (I write the programs using the pyglet wrapper PsychoPy). That is, the program runs locally and the data is stored locally. Now I would like to know if there is a way to use Python to display a (local) website with html-forms to the user and collect the input (locally). The reason for this idea is that currently whenever I want to display checkboxes, radiobuttons

jQuery: password field with readable label?

我们两清 提交于 2019-12-03 21:26:36
I wrote this very simple function for my current project called insidelabel() that let's me add a description (label) for an input field inside of the input. //Label inside of inputfields function insidelabel(selector, name) { $(selector).val(name); $(selector).css({'color':'#999'}); $(selector).focus(function () { //Input Value if ($(this).val() == name) { $(this).val(''); } $(this).css({'color':'#000'}) }); $(selector).blur(function () { if ($(this).val() == '') { $(this).val(name); } if ($(this).val() == name) { $(this).css({'color':'#999'}); } }); } insidelabel('.t', 'name'); insidelabel('

bash user input if

这一生的挚爱 提交于 2019-12-03 18:59:09
问题 I am tring to do simple Do you want to do that? [Y,n] _ question in bash. i tried echo "Do that? [Y,n]" read DO_THAT if ["DO_THAT"="y"]; then do_that fi but it fails: bash: [y=y]: command not found what am I doing wrong??! 回答1: You might consider explicit prompting: -p and specifying 1-character-input -n1 which allows to insert y without ENTER. read -n1 -p "Do that? [y,n]" doit case $doit in y|Y) echo yes ;; n|N) echo no ;; *) echo dont know ;; esac 回答2: echo "Do that? [Y,n]" read input if [[

Manual input from user while running selenium IDE script

独自空忆成欢 提交于 2019-12-03 17:26:22
问题 can user is able to give manual input while running selenium IDE script? For ex. If there is name field then can we open input box everytime script runs so that user can give his input for name field? Let me know whether it is possible or not.. If yes then please suggest me a solution. Thanks in advance 回答1: You can use the following script to invoke a javascript prompt in order to get the value <tr> <td>storeEval</td> <td>prompt("Please enter your FirstName")</td> <td>firstName</td> </tr>

Java ArrayList, taking user input of multiple types(int, String etc.) in one line

帅比萌擦擦* 提交于 2019-12-03 16:56:44
I'm working on getting a little better at Java, and a problem I've run into is taking user input, all in one line like this: System.out.println("Please input numbers that you would like to work with"); //Read in user input into ArrayList, taking into account that they may input Strings or anything else. Assuming the user inputs something like this 1, 2, 4, 257, dog, rabbit, 7, # or even 1 2 4 257 dog rabbit 7 # I've seen in several places how to read in one input at a time, but I wasn't sure of the best way to read in a dynamic ArrayList all at once. I'm not really concerned with the