Script (not working in ash):
#!/bin/sh FILENAME="status.txt" LINENUM=0 REGEX="^(CLIENT_LIST)(.+)" while read SINGLELINE do LINENUM=$((LINENUM+1)) if [[ $SINGLELINE =~ $REGEX ]]; then NUM_CLIENT=$((NUM_CLIENT+1)) echo "Match CLIENT_LIST: $LINENUM" else echo "No match: $LINENUM" fi done < "$FILENAME"
In my terminal:
$ ./status.sh
sh: 2.3.6: unknown operand
Script (working under bash):
#!/opt/bin/bash FILENAME="status.txt" LINENUM=0 REGEX="^(CLIENT_LIST)(.+)" while read SINGLELINE do LINENUM=$((LINENUM+1)) if [[ $SINGLELINE =~ $REGEX ]]; then NUM_CLIENT=$((NUM_CLIENT+1)) echo "Match CLIENT_LIST: $LINENUM" else echo "No match: $LINENUM" fi done < "$FILENAME"
$ ./status.sh
./status.sh
No match: 1
No match: 2
No match: 3
Match CLIENT_LIST: 4
No match: 5
No match: 6
No match: 7
Tip from: http://forum.synology.com/enu/viewtopic.php?f=27&t=77899
No comments:
Post a Comment