반응형
문자열에 다른 문자열이 포함되어 있지 않은지 확인하는 Bash
.sh 스크립트에 문자열 ${testmystring}
이 있고이 문자열 에 다른 문자열이 포함되어 있지 않은지 확인하고 싶습니다.
if [[ ${testmystring} doesNotContain *"c0"* ]];then
# testmystring does not contain c0
fi
어떻게 할 수 있습니까? 즉, doesNotContain은 무엇입니까?
사용 !=
.
if [[ ${testmystring} != *"c0"* ]];then
# testmystring does not contain c0
fi
자세한 내용은를 참조하십시오 help [[
.
메인 프레임 러가 말했듯이 grep을 사용할 수 있지만 테스트를 위해 종료 상태를 사용하려면 다음을 시도하십시오.
#!/bin/bash
# Test if anotherstring is contained in teststring
teststring="put you string here"
anotherstring="string"
echo ${teststring} | grep --quiet "${anotherstring}"
# Exit status 0 means anotherstring was found
# Exit status 1 means anotherstring was not found
if [ $? = 1 ]
then
echo "$anotherstring was not found"
fi
참조 URL : https://stackoverflow.com/questions/30557508/bash-checking-if-string-does-not-contain-other-string
반응형
'IT이야기' 카테고리의 다른 글
데이터베이스 크기가 2GB보다 크면 SQLite 성능이 저하? (0) | 2021.04.26 |
---|---|
Express.js의 MEAN 스택 역할 (0) | 2021.04.26 |
컴파일 및 실행을 위한 CLion 설정 (0) | 2021.04.26 |
react-router가 자식 구성 요소에서 this.props.location을 가져옵니다. (0) | 2021.04.26 |
새로운 Facebook 앱-FBML 또는 iFrame (0) | 2021.04.25 |