Troubleshooting of Sonar issue: Difference between revisions

Jump to navigation Jump to search
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 "使用方法:./add_newline_to_php_files.sh [目錄路徑]"
     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"


# 遍歷指定目錄下的所有 .php 檔案
# 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>
Anonymous user

Navigation menu