Troubleshooting of Sonar issue: Difference between revisions
Jump to navigation
Jump to search
→How to resolve "Add a new line at the end of this file."
mNo edit summary |
|||
| Line 13: | Line 13: | ||
#!/bin/bash | #!/bin/bash | ||
# | # Check if a directory path argument has been provided | ||
if [ "$#" -ne 1 ]; then | if [ "$#" -ne 1 ]; then | ||
echo " | echo "Usage: ./add_newline_to_php_files.sh [Directory Path]" | ||
exit 1 | exit 1 | ||
fi | fi | ||
# | # Retrieve the directory path argument | ||
dir_path="$1" | dir_path="$1" | ||
# | # Iterate through all .php files in the specified directory | ||
for file in "$dir_path"/*.php; do | for file in "$dir_path"/*.php; do | ||
# | # Check if the file exists | ||
if [ -f "$file" ]; then | if [ -f "$file" ]; then | ||
# | # Read the last line of the file | ||
last_line=$(tail -n 1 "$file") | last_line=$(tail -n 1 "$file") | ||
# | # Check if the last line is empty | ||
if [ "$last_line" != "" ]; then | if [ "$last_line" != "" ]; then | ||
# | # If it's not empty, append a newline character | ||
echo "" >> "$file" | echo "" >> "$file" | ||
fi | fi | ||
fi | fi | ||
done | done | ||
</pre> | </pre> | ||