Score:0

In shell scripting how can I take user input for a variable and match and validate the values?

tn flag

Arr=(exv err tmp)
Arr_1=(7 5 5)

In this I want to take input from the user so that it can validate arr and arr_1 value from the array. And if it no matches with the user input it throw an error. I came up with

#!/bin/bash
Select a in arr[@]; do
If [[ "arr[@]" == *"a"* ]]; then
echo ""
break
else 
echo ""
fi
Done

Is there any other method from which I can achieve same result?

Liso avatar
sd flag
Just curious, if you want take input, shouldn't you be using `read` instead of `select` ?
Fox Chasin avatar
tn flag
I already have input defined. I just want to match the one I entered in terminal with the defined one.
hr flag
It's hard to guess what "same result" means, since you haven't actually provided anything workable
Liso avatar
sd flag
@FoxChasin "Entered in terminal", I mean you take user input right ? The way I understand, you want to: 1. User to type to terminal 2. Return success if found in array 3. Return error if not found in array. Am I right ?
Fox Chasin avatar
tn flag
@Liso yes you got right.
Fox Chasin avatar
tn flag
I am using select for doing this . Is there any other way?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.