~percona-toolkit-dev/percona-toolkit/fix-empty-table-bug-987393

« back to all changes in this revision

Viewing changes to lib/bash/alt_cmds.sh

  • Committer: Daniel Nichter
  • Date: 2012-04-03 16:14:55 UTC
  • mfrom: (217.6.22 2.0.3)
  • Revision ID: daniel@percona.com-20120403161455-ntv33vju9o6njtqv
Merge summary-tools-2.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
   fi
44
44
}
45
45
 
 
46
 
 
47
# We don't get things like "which: command not found", so for the pathological
 
48
# case where /usr/bin/which isn't installed, we check that "which which" and
 
49
# if which really isn't there then just return the command passed in and hope
 
50
# they are somewhere
 
51
 
 
52
# TODO:
 
53
#  we just need to redirect STDERR when we execute 
 
54
#  "which" and check it. Some shells are really weird this way. We 
 
55
#  can't check "which"'s exit status because it will be nonzero if 
 
56
#  the sought-for command doesn't exist.
 
57
46
58
_which() {
47
59
   # which on CentOS is aliased to a cmd that prints extra stuff.
48
60
   # Also, if the cmd isn't found, a msg is printed to stderr.
49
 
   [ -x /usr/bin/which ] && /usr/bin/which "$1" 2>/dev/null | awk '{print $1}'
 
61
   if [ -x /usr/bin/which ]; then
 
62
      /usr/bin/which "$1" 2>/dev/null | awk '{print $1}'
 
63
   elif which which 1>/dev/null 2>&1; then
 
64
      # Well, this is bizarre. /usr/bin/which either doesn't exist or
 
65
      # isn't executable, but the shell can use which just fine.
 
66
      # So we bite the bullet, hope that it doesn't do anything
 
67
      # insane, and use it.
 
68
      which "$1" 2>/dev/null | awk '{print $1}'
 
69
   else
 
70
      # We don't have which. Just return the command that was
 
71
      # originally passed in.
 
72
      echo "$1"
 
73
   fi
50
74
}
51
75
 
52
76
# ###########################################################################