Files
linux-sysadmin-journey/projects/02-command-line-mastery/verify-scripts.sh
T

34 lines
757 B
Bash
Raw Normal View History

2025-02-09 02:33:45 -06:00
#!/bin/bash
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
# Get project directory
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Function to verify a shell script
verify_script() {
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}"
return 1
fi
echo -e "${GREEN}Syntax OK${NC}"
return 0
}
# Find and verify all shell scripts
find "$PROJECT_DIR" -type f -name "*.sh" -exec bash -c 'verify_script "$0"' {} \;