我试着用这个
if `$(egrep '(cinta|aduh|siapa)' $inputFile)` ; then
filter='love'
else `$(egrep '(kok|aku|dan)' $inputFile)` ; then
filter='jangan'
else `$(egrep '(mari)' $inputFile)`; then
filter='mari'
else `$(egrep '(kerumah|bebeb)' $inputFile)`; then
filter='bebeb'
else `$(egrep '*' $inputFile)`; then
filter='other'
fi
Run Code Online (Sandbox Code Playgroud)
但我得到了结果
./amosv5: line 175: syntax error near unexpected token `then'
./amosv5: line 175: ` then'
Run Code Online (Sandbox Code Playgroud)
为什么我收到此错误.
我需要在php中这样做
if (strpos($inputfile, "cinta") || strpos($inputfile, "aduh") || strpos($inputfile, "siapa") {
$filter = 'love';
} else { $filter = 'other'; } }
Run Code Online (Sandbox Code Playgroud)
语法是完全错误的!
您可以直接在条件上使用大多数 shell实用程序的返回代码bash
.在第一个条件中egrep
,cinta|aduh|siapa
如果能够找到任何模式,则多个模式匹配将返回true .同样,这可以用于其余部分.
if egrep 'cinta|aduh|siapa' "$inputFile" ; then
filter='love'
elif egrep 'kok|aku|dan' "$inputFile" ; then
filter='jangan'
..
Run Code Online (Sandbox Code Playgroud)