Skip to content

Instantly share code, notes, and snippets.

@dai0304
Created May 20, 2011 02:30
Show Gist options
  • Save dai0304/982239 to your computer and use it in GitHub Desktop.
Save dai0304/982239 to your computer and use it in GitHub Desktop.
#!/bin/bash
STR=ABC-0
if [[ "$STR" =~ "-0$" ]]; then
echo A
else
echo B
fi
@dai0304
Copy link
Author

dai0304 commented May 20, 2011

$ bash --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
$ ./test.sh
A

↑バージョン差異↓ が原因だろうか。bash v4の方で、結果をAにするにはどうしたらいいだろうか?

$ bash --version
GNU bash, version 4.1.7(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ ./test.sh
B

@dai0304
Copy link
Author

dai0304 commented May 20, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment