我正在~/.bashrc
编写Linux bash函数,为我自动执行某些操作
#!/bin/bash
......
......
function cog102start
{
LD_LIBRARY_PATH=/opt/ibm/cognos/c102_6/cgi-bin
httpd64start
DB2START=$(sudo -u db2inst1 /home/db2inst1/sqllib/adm/db2start)
________need something here_________
}
DB2START
的输出将包含
SQL1036N DB2START process was successful
或
SQL1026N The database manager is already active
如何测试if语句以决定下一步做什么?
我正在尝试
if [ [ $DB2START =~ ^(SQL1036N|SQL1026N)$ ] ]; then dosomething; fi
给我一个语法错误......我不知道还有什么可以尝试。
答案 0 :(得分:3)
正确的语法是
if [[ $DB2START =~ ^(SQL1036N|SQL1026N)$ ]]; then dosomething; fi
[[
和]]
是单一令牌;两者之间不允许有空格。
答案 1 :(得分:2)
if [ [ $DB2START =~ ^(SQL1036N|SQL1026N)$ ] ]; then dosomething; fi ^ ^ \ / --- no space here or here ---