0
下面的代碼應該逐行打印sourceFile的內容到targetFile,每行都有「wireless-key s:」,但它只打印「wireless-鍵s:'到目標文件。Bash腳本 - sourceFile不打印到目標文件
#!/bin/bash
sourceFile="file1.log"
targetFile="/etc/network/interfaces"
numLines="$(wc -l < "${sourceFile}")"
counter=5
lineNumber=5
if ((counter >= "$numLines")) || [[ ! -f "${sourceFile}" ]]; then
echo "invaild file" >82; exit 1
fi
while [ "$counter" -le "$numLines" ]; do
sed -i "${lineNumber} s/.*/wireless-key s: $(sed -n ${counter}p <<< " ${sourceFile}")/" "${targetFile}"
counter=$((counter + 1))
done
謝謝
謝謝它效果很好 – spbr