Skip to content

Commit 1e27ad6

Browse files
authored
Merge pull request #22 from wendelscardua/fix-sensor-args
Prevent sensor names from being splitted when they contain spaces
2 parents f30f55c + 9c89d58 commit 1e27ad6

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

scripts/termux-sensor

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ handle_interrupt () {
3838
cleanup () {
3939
if [ $((FLAGS & (ALL_SENSORS_FLAG | SENSOR_FLAG))) != 0 ]; then
4040
echo "Performing sensor cleanup"
41-
call_api "-a cleanup"
41+
call_api -a cleanup
4242
else
4343
echo "No cleanup necessary"
4444
fi
@@ -59,7 +59,7 @@ get_delay () {
5959
}
6060

6161
call_api () {
62-
/data/data/com.termux/files/usr/libexec/termux-api Sensor $@
62+
/data/data/com.termux/files/usr/libexec/termux-api Sensor "$@"
6363
}
6464

6565
set_flag () {
@@ -73,16 +73,16 @@ usage_error () {
7373
}
7474

7575

76-
PARAMS=""
76+
PARAMS=()
7777
while getopts :h,a,c,l,s:d: option
7878
do
7979
case "$option" in
8080
h) show_usage ;;
81-
a) set_flag $ALL_SENSORS_FLAG; PARAMS="-a sensors $PARAMS --ez all true" ;;
82-
c) set_flag $CLEANUP_FLAG; PARAMS="-a cleanup" ;;
83-
l) set_flag $LIST_FLAG; PARAMS="-a list" ;;
84-
s) set_flag $SENSOR_FLAG; get_sensors $OPTARG; PARAMS="-a sensors --es sensors $OPTARG" ;;
85-
d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS="$PARAMS --ei delay $OPTARG" ;;
81+
a) set_flag $ALL_SENSORS_FLAG; PARAMS+=(-a sensors --ez all true);;
82+
c) set_flag $CLEANUP_FLAG; PARAMS=(-a cleanup) ;;
83+
l) set_flag $LIST_FLAG; PARAMS=(-a list) ;;
84+
s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS+=(-a sensors --es sensors "$OPTARG") ;;
85+
d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS+=(--ei delay $OPTARG) ;;
8686
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
8787
esac
8888
done
@@ -100,4 +100,4 @@ elif [ $((FLAGS & ALL_SENSORS_FLAG)) -ne 0 ] && [ $((FLAGS & SENSOR_FLAG)) -ne 0
100100
usage_error "Listed sensors will be ignored with -a all option!"
101101
fi
102102

103-
call_api $PARAMS
103+
call_api "${PARAMS[@]}"

0 commit comments

Comments
 (0)