FS#16623 - Replace the old [ test with the bash builtin [[ and (( for numeric stuff
Attached to Project:
Pacman
Opened by Isaac G (IsaacG) - Tuesday, 13 October 2009, 19:16 GMT
Last edited by Xavier (shining) - Saturday, 28 November 2009, 16:04 GMT
Opened by Isaac G (IsaacG) - Tuesday, 13 October 2009, 19:16 GMT
Last edited by Xavier (shining) - Saturday, 28 November 2009, 16:04 GMT
|
Details
To quote from the #bash factoids,
[[ is a bash keyword similar to (but more powerful than) the [ command. See http://mywiki.wooledge.org/BashFAQ/031 and http://mywiki.wooledge.org/BashGuide#Bash_Tests Unless you are scripting for POSIX sh we recommend [[. and When evaluating arithmetic expressions, use (( expr )), not [ ] or [[ ]]. See http://mywiki.wooledge.org/ArithmeticExpression The [[ runs about twice as fast as [ and is cleaner. bash also has (( for numeric tests. Some examples for the makepkg that can be fixed: if [ -z "$1" ]; then to if [[ ! $1 ]]; then if [ "$LOGGING" -eq 1 ]; then to if (( LOGGING == 1 )); then if [ $ret -gt 0 ]; then to if (( ret > 1 )); then or if (( ret )); then if [ $EXIT_CODE -eq 0 -a "$CLEANUP" -eq 1 ]; then to if (( EXIT_CODE == 0 && CLEANUP == 1 )); then or possibly if (( EXIT_CODE == 0 && CLEANUP )); then |
This task depends upon
Closed by Xavier (shining)
Saturday, 28 November 2009, 16:04 GMT
Reason for closing: Implemented
Additional comments about closing: implemented in git; commits 966c815 and c299961
Saturday, 28 November 2009, 16:04 GMT
Reason for closing: Implemented
Additional comments about closing: implemented in git; commits 966c815 and c299961
IsaacG might be willing to make a patch if everyone is fine with it.
Are you willing to make us a patch for this?
$ type [
[ is a shell builtin
$ type [[
[[ is a shell keyword
But [[ is faster than [.
$ s=hi; time for i in {1..100000} ; do [[ $s = "hi" ]] ; done ; time for i in {1..100000} ; do [ "$s" = "hi" ] ; done
The user times I get for [ and double for [[. bash does parse the two differently.
http://www.archlinux.org/pacman/submitting-patches.html
I did the git commit -s and git format-patch but I didn't see any patch file produced. git show [commit hash] produced this file...
I'm supposed to also email this to the dev list?
git format-patch HEAD^
to get the patch file, and yes, you should send this to pacman-dev (via git send-email or inline).
See also doc/submitting-patches.txt in pacman's git tree.