fork(1) download
  1. #!/bin/bash
  2.  
  3. doContain() {
  4. reqsubstr="$1"
  5. shift
  6. string="$@"
  7. if [ -z "${string##*$reqsubstr*}" ] ;then
  8. # echo "String '$string' contain substring: '$reqsubstr'.";
  9. true
  10. else
  11. # echo "String '$string' don't contain substring: '$reqsubstr'."
  12. false
  13. fi
  14. }
  15.  
  16. export -f doContain
  17.  
  18. nst='a=two;b=onetwothree; x=100000; while [ $x -gt 0 ]; do TEST ; x=$(($x-1)); done'
  19. nst='a=nonesvch;
  20. b=nosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatchnosuchmatch;
  21. for((x=0; x<10000; ++x)); do TEST && { echo FAIL; exit 127; }; done'
  22. :<<\=cut
  23. for TEST in '[[ $b =~ $a ]]' '[ "${b/$a//}" = "$b" ]' '[[ $b == *$a* ]]' \
  24. 'case $b in *$a*):;;esac' 'doContain "$a" "$b"'; do
  25. printf '%s ' "$TEST"
  26. /usr/bin/time bash -c "${nst/TEST/$TEST}"
  27. done
  28. =cut
  29. for TEST in '[[ $b =~ $a ]]' '! [ "${b/$a//}" = "$b" ]' '[[ $b == *$a* ]]' \
  30. 'case $b in *$a*):;; *) false;; esac' 'doContain "$b" "$a"'; do
  31. printf '%s ' "$TEST" >&2
  32. time bash -c "${nst/TEST/$TEST}"
  33. done
  34.  
Runtime error #stdin #stdout #stderr 0.94s 4540KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
[[ $b =~ $a ]] 
real	0m0.168s
user	0m0.164s
sys	0m0.000s
! [ "${b/$a//}" = "$b" ] 
real	0m0.233s
user	0m0.232s
sys	0m0.000s
[[ $b == *$a* ]] 
real	0m0.086s
user	0m0.084s
sys	0m0.000s
case $b in *$a*):;; *) false;; esac 
real	0m0.094s
user	0m0.092s
sys	0m0.000s
doContain "$b" "$a" 
real	0m0.369s
user	0m0.368s
sys	0m0.000s