相关疑难解决方法(0)

如何使用/ bin/sh检查模式匹配,而不是/ bin/bash

我正在使用Ubuntu系统shell,而不是bash,我发现常规方式无法正常工作:

#!/bin/sh
string='My string';

if [[ $string =~ .*My.* ]]
then
   echo "It's there!"
fi
Run Code Online (Sandbox Code Playgroud)

错误[[:找不到!

我该怎么做才能解决这个问题?

shell

16
推荐指数
3
解决办法
2万
查看次数

shell 测试运算符正则表达式

#!/bin/bash
# This file will fix the cygwin vs linux paths and load programmer's notepad under windows.
# mail : <sandundhammikaperera@gmail.com> 
# invokes the GNU GPL, all rights are granted.


# check first parameter is non empty.
# if empty then give a error message and exit.
file=${1:?"Usage: pn filename"};

if [[ "$file" == /*/* ]] ;then
  #if long directory name.
# :FAILTHROUGH:
  echo "$0: Executing pn.exe $file" 

else 
  file="$(pwd)/$file";
fi

#check whether the filename starts with / if so …
Run Code Online (Sandbox Code Playgroud)

regex shell

4
推荐指数
1
解决办法
5940
查看次数

标签 统计

shell ×2

regex ×1