“Проверка пробела для подстроения в строке” Ответ

Бэш, если подстроение

string='Hi substring' #To check if string has "Mylong" substring do
if [[ $string == *"substring"* ]]; then
  echo "String has substring"
fi
Armandres

Проверка, существует ли подстроение в струнке

string='Haystack';

if [[ $string =~ "Needle" ]]
then
   echo "It's there!"
fi
Clumsy Coyote

Bash, если подстроение в строке

# Example usage:
FULLSTRING='Full string to search'
if [[ $FULLSTRING == *"ll str"* ]]; then
	echo "The substring 'll str' is in the full string."
fi

# Example to check for two substrings:
FULLSTRING='Full string to search'
if [[ $FULLSTRING == *"Full"* && $FULLSTRING == *"to"* ]]; then
	echo "The substrings 'Full' and 'to' are in the full string."
fi

# Note, see the following two links for why [[ ]] is used:
https://serverfault.com/questions/52034/what-is-the-difference-between-double-and-single-square-brackets-in-bash
http://mywiki.wooledge.org/BashFAQ/031
Charles-Alexandre Roy

Проверка пробела для подстроения в строке

[[ $haystack =~ "Needle" ]]
Brian Patterson

Ответы похожие на “Проверка пробела для подстроения в строке”

Вопросы похожие на “Проверка пробела для подстроения в строке”

Больше похожих ответов на “Проверка пробела для подстроения в строке” по Shell/Bash

Смотреть популярные ответы по языку

Смотреть другие языки программирования