-
Notifications
You must be signed in to change notification settings - Fork 0
Error Codes
Mikhail Deynekin edited this page Apr 11, 2026
·
1 revision
Complete reference for all exit codes returned by sr.
| Code | Meaning | Typical Scenario |
|---|---|---|
0 |
Success | Replacements completed successfully |
1 |
Invalid arguments | Missing or incorrect parameters |
2 |
No files found | Pattern didn't match any files |
3 |
No replacements | Search string not found in any files |
4 |
Runtime error | Permission issues, disk full, etc. |
5 |
Backup failed | Couldn't create backup files |
6 |
Binary file detected | Binary file encountered without --binary flag |
7 |
Rollback failed | Restoration encountered errors |
The operation completed successfully. All found matches were replaced and backups were created.
sr "*.txt" "hello" "world"
echo $? # Returns 0The command was invoked with incorrect arguments.
Common causes:
- Missing required arguments (pattern, search, replace)
- Invalid option flags
- Conflicting options
# Check usage
sr --help
# Correct syntax
sr [OPTIONS] "FILE_PATTERN" "SEARCH" "REPLACE"The file pattern didn't match any files.
Common causes:
- Pattern not quoted (shell expanded it)
- Wrong directory
- No files match the pattern
# Debug: check what files exist
find . -name "*.txt" -type f | head
# Fix: quote the pattern
sr "*.txt" "search" "replace"Files were found but the search string wasn't found in any of them.
Common causes:
- Search string doesn't match (case sensitivity)
- Pattern matches wrong files
- String already replaced
# Debug: search manually
grep -r "search_string" .
# Fix: use case-insensitive
sr -i "*.txt" "search" "replace"An error occurred during execution.
Common causes:
- Permission denied on files
- Disk full
- Missing required utilities
# Check disk space
df -h .
# Check file permissions
ls -la *.txt
# Check required utilities
for cmd in bash find sed grep; do command -v $cmd; doneThe backup system failed to create backups before modification.
Common causes:
- No write permission in current directory
- Disk full
- Target directory doesn't exist
# Check write permissions
ls -la .
# Use no-backup as workaround (RISKY!)
sr -nb "*.txt" "search" "replace"sr detected a binary file and refused to process it without explicit permission.
# Check if file is actually binary
file suspicious-file
# Process binary file explicitly (use with caution)
sr --binary "*.bin" "search" "replace"
# Exclude binary file types
sr -xp "*.png,*.jpg,*.exe" "**/*" "search" "replace"The rollback operation encountered errors restoring files.
Common causes:
- Backup directory corrupt or missing
- Permission denied restoring files
- Backup files modified externally
# List available backups
sr --rollback-list
# Try specific backup
sr --rollback=sr.backup.20240115_143022
# Manual restore from backup directory
cp sr.backup.20240115_143022/files/path/to/file.txt ./path/to/file.txt#!/bin/bash
# Example: Use exit codes for error handling
sr --dry-run "*.conf" "old-server" "new-server"
DRY_RUN_EXIT=$?
case $DRY_RUN_EXIT in
0) echo "Files found and would be modified"; ;;
2) echo "No matching files found"; exit 1; ;;
3) echo "Search string not found"; exit 0; ;;
*) echo "Unexpected error: $DRY_RUN_EXIT"; exit 1; ;;
esac
# If dry-run looks good, apply changes
sr "*.conf" "old-server" "new-server"
if [ $? -eq 0 ]; then
echo "Success!"
else
echo "Failed, rolling back..."
sr --rollback
fi- Troubleshooting - Common issues and solutions
- Command Reference - Complete option listing
- FAQ - Frequently asked questions