1
0

shell.sh 528 B

12345678910111213141516171819202122232425262728293031323334353637
  1. getvar() {
  2. eval "echo \"\${$1}\""
  3. }
  4. var2file() {
  5. local var
  6. eval "var=\"\${$1}\""
  7. if [ -n "$var" ]; then echo "$var" > "$2"; fi
  8. }
  9. isset() {
  10. local var
  11. eval "var=\"\${$1}\""
  12. [ -n "$var" ]
  13. }
  14. trapret() {(
  15. local retvals="$1"; shift
  16. local cmd="$1"; shift
  17. for retval in $(echo $retvals); do
  18. local trap_$retval=1
  19. done
  20. "$cmd" "$@" || {
  21. local retval="$?"
  22. eval "trapped=\${trap_$retval}"
  23. [ -n "$trapped" ] || {
  24. return $retval
  25. }
  26. }
  27. )}
  28. md5s() {
  29. cat "$@" | (
  30. md5sum 2>/dev/null ||
  31. md5
  32. ) | awk '{print $1}'
  33. }