How to bash or shell after running the command "echo df | gnokii --sendsms 73459045567" to check the sending of SMS? I mean to write the result of the execution into a variable and then see if the keyword is there: "succeeded". Since it shows the text in the terminal: "Send succeeded!". I tried to write to a variable, but for some reason it returns void anyway.

  • Please attach a sample code so that you can see what you were trying to do and what you did wrong. - Igor Adamenko

2 answers 2

It is difficult to say what exactly you had a mistake.

  1. I did not understand what my , but I hadn’t written on a bash for a long time, maybe something new had been introduced there.
  2. At assignment, variables are specified without a dollar sign.
  3. There are no spaces around = when assigning.
  4. gnokii throws everything out of error in stdout, but in stderr, this should be taken into account and redirected.
  5. Further generally some PHP went. It feels like I did not understand what you need.

However, this code works for me:

 msg="Yo nigga wazzup?" phone="79001234567" result=$(echo $msg | gnokii --sendsms $phone 2>&1) if [[ $result == *"succeeded"* ]]; then echo "Успешная отправка" else echo -e "Ошибка отправки на номер $phone \n" fi 
  • maybe there is something new introduced - not entered. this is the author of the question tried to invent a new language "perl-i-sh". - aleksandr barakin
 my $result = `echo $msg | gnokii --sendsms $phone`; if ($result=~/succeeded/){ print "успешная отправка" }else{ print "Ошибка отправки на номер ".$phone."\n"; } 

But for some reason, in my $ result variable, the void is anyway.