with the below code I keep getting the following errors:
#!/bin/bash
sourceFile="file1.log"
targetFile="/etc/network/interfaces"
numLines=$(wc -l ${sourceFile})
if (( counter >= "$numLines" || ! -f "${sourceFile}" )); then
echo "invaild file"
exit 0
fi
while [ "$counter" -le "$numLines" ]; do
sed -i "${2} s/.*/wireless-key s: $(sed -n "${counter}"p <<< "${sourceFile}")/" "${targetFile}"
counter=$((counter + 1))
done
with the above code I keep getting the following errors:
> ./2test.sh: line 5: ((: counter >= 12 file1.log || ! -f file1.log : syntax error: invalid arithmetic operator (error token is ".log || !
> -f file1.log ") ./2test.sh: line 9: [: : integer expression expected
wc -l ${sourceFile}prints12 file1.log, so that's the value of$numLines.numLines="$(wc -l < "${sourceFile}")"should give you just the number (the quotes are free this week, enjoy).echo 'invalid file' >&2; exit 1would be more appropriate. Errors should be printed to stderr, and the script ought to return non-zero if it fails.! -f "${sourceFile}"is not valid code in(()), maybe try it in square brackets i.e(( counter >= "$numLines" )) || [[ ! -f "${sourceFile}" ]]