Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 Unix 脚本(.ksh)很陌生。我必须实现一个功能来检查我的参数是否说“欢迎”存在于字符串数组中,例如
{"welcome","test","exit"}
逻辑类似于String.containsJava。
String.contains
任何帮助将不胜感激。
你可以做这样的事情。以下是在bash,您需要将其相应更改为ksh。
bash
ksh
array=(welcome test exit) string='welcome'; for item in ${array[*]} do if [[ $string =~ .*$item.* ]] then echo "It's present!" fi done
It's present!
要迭代传递给 shell 脚本的参数,请使用 for with empty in,默认迭代参数,或in '$@'.
in '$@'