select.sh 391 B

123456789101112131415161718192021222324
  1. #! /bin/sh
  2. ## Change the currently active card
  3. TOPIC="/card"
  4. toSingleLine () {
  5. echo $(echo $1 | tr -s '\t' ' ' | tr -d '\n')
  6. }
  7. if [ "$1" == "" ]; then
  8. echo "ERROR: expecting direction argument: [left|right|first|last]"
  9. exit
  10. fi
  11. json='{
  12. "cmd":"select_card",
  13. "action": "'"$1"'"
  14. }'
  15. echo "$json"
  16. json=$(toSingleLine "$json")
  17. mosquitto_pub -t $TOPIC -m "$json"