v-list-sys-shells 1.6 KB

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