v-list-sys-shells 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # info: list system shells
  3. # options: [FORMAT]
  4. # labels: panel
  5. #
  6. # example: v-list-sys-shells
  7. #
  8. # The function for obtaining the list of system shells.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. format=${1-shell}
  14. # Includes
  15. source $HESTIA/func/main.sh
  16. # JSON list function
  17. json_list() {
  18. sh_counter=$(echo "$shells" | wc -l)
  19. i=1
  20. echo '['
  21. for shell in $shells; do
  22. if [ "$i" -lt "$sh_counter" ]; then
  23. echo -e "\t\"$shell\","
  24. else
  25. echo -e "\t\"$shell\""
  26. fi
  27. (( ++i))
  28. done
  29. echo "]"
  30. }
  31. # SHELL list function
  32. shell_list() {
  33. echo "SHELL"
  34. echo "-----"
  35. for shell in $shells; do
  36. echo "$shell"
  37. done
  38. }
  39. # PLAIN list function
  40. plain_list() {
  41. for shell in $shells; do
  42. echo "$shell"
  43. done
  44. }
  45. # CSV list function
  46. csv_list() {
  47. echo "SHELL"
  48. for shell in $shells; do
  49. echo "$shell"
  50. done
  51. }
  52. #----------------------------------------------------------#
  53. # Action #
  54. #----------------------------------------------------------#
  55. # Defining system shells
  56. shells=$(grep -v '#' /etc/shells |awk -F '/' '{print $NF}' |sort -u)
  57. # Listing data
  58. case $format in
  59. json) json_list ;;
  60. plain) plain_list ;;
  61. csv) csv_list ;;
  62. shell) shell_list ;;
  63. esac
  64. #----------------------------------------------------------#
  65. # Hestia #
  66. #----------------------------------------------------------#
  67. exit