-
Notifications
You must be signed in to change notification settings - Fork 0
Basic Examples
Practical examples for common Clean BOM Senior tasks. Focus on the simplified syntax: ./clean-bom-senior.sh "[PATH]" --options and the workflow of remove BOMs and fix line endings.
- Core Principle
- Basic Commands
- Single File Processing
- Batch Processing
- Common Use Cases
- Advanced Examples
- Troubleshooting
- Best Practices
- Next Steps
Clean BOM Senior is designed for simplicity:
./clean-bom-senior.sh [PATH] [OPTIONS]Where:
-
[PATH]= File or directory to process -
[OPTIONS]=--dry-run,--backup,--verbose,--fix-crlf, etc.
Process one file and remove UTF-8 BOM:
./clean-bom-senior.sh document.phpProcess all files in current directory:
./clean-bom-senior.sh .Use dry-run mode to see what would change:
./clean-bom-senior.sh . --dry-runAutomatically backup files before modification:
./clean-bom-senior.sh . --backupDisplay detailed processing information:
./clean-bom-senior.sh . --verboseView all available options:
./clean-bom-senior.sh --helpProblem: PHP file with UTF-8 BOM causes "headers already sent" error
./clean-bom-senior.sh config.php --verboseOutput:
✓ config.php: BOM removed (UTF-8)
Problem: JSON files with BOM fail to parse
./clean-bom-senior.sh data.jsonProblem: Python interpreter rejects encoding declaration with BOM
./clean-bom-senior.sh script.py --verboseProblem: File has both BOM and Windows (CRLF) line endings
./clean-bom-senior.sh config.ini --fix-crlf --backupThis removes BOM and converts CRLF → LF
Remove BOM from all .php files in directory:
./clean-bom-senior.sh . --file-type php --verbose./clean-bom-senior.sh . --file-type ini
./clean-bom-senior.sh . --file-type conf
./clean-bom-senior.sh . --file-type yamlRemove BOM from all files except those in .git and node_modules:
./clean-bom-senior.sh . --exclude .git --exclude node_modules --backupRecursively process all subdirectories:
./clean-bom-senior.sh src/ --verboseProcesses: src/ and all subdirectories
Get detailed statistics:
./clean-bom-senior.sh . --verbose --backupShows:
- Files processed
- BOM types detected
- Line ending issues
- Summary statistics
Scenario: Files exported from Windows with BOMs and CRLF endings
# Step 1: Preview changes
./clean-bom-senior.sh . --dry-run --fix-crlf
# Step 2: Apply with backup
./clean-bom-senior.sh . --fix-crlf --backup --verbose
# Step 3: Restore if needed
./clean-bom-senior.sh . --restoreScenario: PHP files have BOMs causing header errors
# Process all PHP files
./clean-bom-senior.sh . --file-type php --backup
# Verify with verbose output
./clean-bom-senior.sh . --file-type php --verboseScenario: Clean all text files before committing
# Dry run first
./clean-bom-senior.sh . --dry-run --verbose
# Create backups and clean
./clean-bom-senior.sh . --backup --fix-gitattributes
# Commit changes
git add .
git commit -m "Remove BOM and fix line endings"Scenario: Markdown files have BOM issues
./clean-bom-senior.sh docs/ --file-type md --backupScenario: Run as part of build process
#!/bin/bash
./clean-bom-senior.sh . --dry-run
if [ $? -eq 0 ]; then
echo "✓ No BOMs found"
else
echo "⚠ BOMs detected, cleaning..."
./clean-bom-senior.sh . --backup
fiScenario: JSON files fail parsing due to BOM
./clean-bom-senior.sh config/ --file-type json --verboseProcess multiple file types:
./clean-bom-senior.sh . --file-type php --backup
./clean-bom-senior.sh . --file-type json --backup
./clean-bom-senior.sh . --file-type yaml --backup./clean-bom-senior.sh src/ \
--file-type php \
--exclude tests \
--exclude vendor \
--fix-crlf \
--backup \
--verboseThis:
- Targets PHP files in src/
- Excludes tests/ and vendor/
- Fixes CRLF line endings
- Creates backups
- Shows detailed output
Best practice for critical systems:
# Step 1: Analyze in dry-run mode
./clean-bom-senior.sh /var/www/html --dry-run --verbose
# Step 2: If results look good, apply
./clean-bom-senior.sh /var/www/html --backup --fix-crlf
# Step 3: Verify application works
# ... test your application ...
# Step 4: Clean up backups if all is good
find /var/www/html -name "*.bak" -deleteIf something went wrong:
# Restore single file
./clean-bom-senior.sh config.php --restore
# Restore all files of type
find . -name "*.php.bak" -exec ./clean-bom-senior.sh {} --restore \;Cause: Script or files lack execute/write permissions
Solution:
# Make script executable
chmod +x clean-bom-senior.sh
# Check file permissions
ls -la file.php
# Fix if needed
chmod 644 file.phpCause 1: Files don't have BOM
# Verify with verbose
./clean-bom-senior.sh . --verboseCause 2: Using wrong file type filter
# Check supported types
./clean-bom-senior.sh --help | grep file-typeSolution: Check exclude syntax
# Correct way
./clean-bom-senior.sh . --exclude .git --exclude node_modules
# Verify with dry-run
./clean-bom-senior.sh . --exclude .git --dry-run --verboseCause: --fix-crlf not included
Solution:
# Include the flag
./clean-bom-senior.sh . --fix-crlf --verbose
# Verify with dry-run first
./clean-bom-senior.sh . --fix-crlf --dry-runSolution: Use --backup flag
# With backup
./clean-bom-senior.sh . --backup
# Verify backups created
ls -la *.bak# Preview
./clean-bom-senior.sh . --dry-run --verbose
# Apply only after verification
./clean-bom-senior.sh . --backup./clean-bom-senior.sh . --backup --verbose./clean-bom-senior.sh . --verboseOutputs:
- File count
- BOM types found
- Processing status
- Error details
For critical systems:
# Clean production files
./clean-bom-senior.sh /app --backup
# Test application
systemctl restart myapp
systemctl status myapp
# If problems, restore
./clean-bom-senior.sh /app --restoreAdd to cron for continuous compliance:
# Daily BOM check
0 2 * * * /path/to/clean-bom-senior.sh /var/www --backup --quiet./clean-bom-senior.sh . \
--exclude .git \
--exclude .svn \
--exclude node_modules \
--exclude vendor \
--exclude .cacheNow you have practical examples to work with. For more information:
- See Quick-Start-Guide for step-by-step guide
- Read Command-Line-Reference for all available options
- Check Understanding-BOM-and-CRLF for technical details
- Learn about File-Types-and-Detection for supported formats
- Visit Troubleshooting-Guide for common issues