Score:0

case statement only reaching the default case

us flag
echo "Choose one or All"
        read -n1 $sel
        echo "value of $sel
        case $selection in 
        o|O) echo "inside O";;
        a|A) echo "inside A";;
        *) echo "this is default"
        ;;
        esac;

However, it always print value of $sel is default. The case statement is always reaching the default value and it is not reaching other cases. What might be the issue?

hr flag
You need to be consistent about whether the variable is `$sel` or `$selection` and also it should be `read -n1 sel` (no `$`). You also have an unmatched `"` which I assume is a copy error.
pLumo avatar
in flag
You might want to check out `select` statement. e.g. `select sel in one all; do break; done; echo $sel;`
Aviator avatar
us flag
@steeldriver fixed all these things now, still no luck.
Aviator avatar
us flag
@plumo this returns empty string
hr flag
@Aviator you may [edit] your question to correct the code. It's really impossible to debug code we can't see.
waltinator avatar
it flag
Always paste your script into `https://shellcheck.net`, a syntax checker, or install `shellcheck` locally. Make using `shellcheck` part of your development process.
pLumo avatar
in flag
@Aviator , you give the number, not the text. So enter "1" or "2" , then enter. And `$sel` will be the `one` or `all`.
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.