From bef0fd2e4b8a46e6cdeb8f561069d8c49336aa71 Mon Sep 17 00:00:00 2001 From: Hugh Ratsch Date: Sun, 9 Feb 2025 02:54:59 -0600 Subject: [PATCH] updated project 2 --- .../02-command-line-mastery/verify-scripts.sh | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/projects/02-command-line-mastery/verify-scripts.sh b/projects/02-command-line-mastery/verify-scripts.sh index e8bcd23..404af81 100644 --- a/projects/02-command-line-mastery/verify-scripts.sh +++ b/projects/02-command-line-mastery/verify-scripts.sh @@ -11,24 +11,38 @@ PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Function to verify a shell script verify_script() { - local script=$1 + local script="$1" echo -e "${BLUE}Checking: ${script}${NC}" # Check if file exists if [[ ! -f "$script" ]]; then - echo -e "${RED}Error: File not found${NC}" - return 1 - } - - # Check shell syntax - if ! bash -n "$script"; then - echo -e "${RED}Syntax error found${NC}" + echo -e "${RED}Error: File not found - $script${NC}" return 1 fi - echo -e "${GREEN}Syntax OK${NC}" + # Check shell syntax + if ! bash -n "$script"; then + echo -e "${RED}Syntax error found in $script${NC}" + return 1 + fi + + # Check for common shell script issues + if command -v shellcheck >/dev/null 2>&1; then + if ! shellcheck "$script"; then + echo -e "${RED}ShellCheck found issues in $script${NC}" + return 1 + fi + fi + + echo -e "${GREEN}Script $script passed verification${NC}" return 0 } +# Main execution +echo "Starting script verification..." + # Find and verify all shell scripts +find "$PROJECT_DIR" -type f -name "*.sh" | while read -r script; do + verify_script "$script" +done find "$PROJECT_DIR" -type f -name "*.sh" -exec bash -c 'verify_script "$0"' {} \; \ No newline at end of file