0

I am very new here, so I apologize for any my mistakes, and I am sorry for my lack of knowledge (I'm just beginner). So here it is, i am doing little script in bash with li and I have if statement, here it is

#!/bin/bash
something=$(whiptail --inputbox "Enter some text" 10 30 3>&1 1>&2 2>&3)
if [ $something ?? 'you' ];
then
    echo "$something"
else
  echo "nope"
fi

To be specific what i want from it - I enter some word/sentence/whatever to whiptail, and if it contains some of of you string then prints it, but every times it goes else ;_;.Please help.

EDIT now it works, thanks but I need to check if string contains word.

if [[ $string =~ .*My.* ]]

doesn't seem to work

2 Answers2

0

I don't get it at all, losing hope and searching the web i've encontered on

#!/bin/bash
OPTION=$(whiptail –title “Menu Dialog” –menu “Choose your option” 15 60 4 \ “1” “Grilled ham” \ “2” “Swiss Cheese” \ “3” “Charcoal cooked Chicken thighs” \ “4” “Baked potatos” 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ];
then echo “Your chosen option:” $OPTION
else echo “You chose Cancel.”
fi

And I've just pasted this script to check how it works and modify it, it isn't mine script and it supposed to work, but it says “You chose Cancel.”

0

What you may be looking for are the string comparison operators like == or !=. For example,

if [ "$something" == "you" ]; then
    echo "$something"
else
  echo "nope"
fi

If $something equals you then echo $something; else echo nope.

Or, as David C.Rankin mentioned in his comment you can check the string variable to prove whether a string is empty or not. For example,

if [ -z "$something"] ;then 

String is empty

if [ -n "$something" ]; then

String is non-empty

For more information on this check the TEST manual page.

Richard Erickson
  • 2,568
  • 8
  • 26
  • 39
Mozzy
  • 281
  • 2
  • 3
  • 12