id.test 999 B

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. # Systems with SELinux will have security context cruft,
  5. # BSDs call the root group "wheel" instead,
  6. # and Raspberry Pi OS has root also in the 117(lpadmin) group.
  7. CLEAN="sed 's/ context=.*//g' | sed 's/wheel/root/g' | \
  8. sed 's/117//g' | sed -E 's/\(?lpadmin\)?//g' | sed 's/[ ,]$//'"
  9. testing "0" "id 0 | $CLEAN" "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
  10. testing "root" "id root | $CLEAN" \
  11. "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
  12. testing "-G root" "id -G root | $CLEAN" "0\n" "" ""
  13. testing "-nG root" "id -nG root | $CLEAN" "root\n" "" ""
  14. testing "-g root" "id -g root" "0\n" "" ""
  15. testing "-ng root" "id -ng root | $CLEAN" "root\n" "" ""
  16. testing "-u root" "id -u root" "0\n" "" ""
  17. testing "-nu root" "id -nu root" "root\n" "" ""
  18. testing "no-such-user" "id no-such-user 2>/dev/null ; echo \$?" "1\n" "" ""
  19. testing "2147483647" "id 2147483647 2>/dev/null ; echo \$?" "1\n" "" ""