Sample Header Ad - 728x90

Hyphen is being replaced by $'\342\200\224...' in bash

2 votes
1 answer
1540 views
I've created a bash script to start a network computer if it is sleeping, then start a streaming client. However, as the script executes the final command to run the streaming client, each cli option with a hyphen becomes wrapped in
$'\342\200\224'
. E.g.
-resolution
becomes
$'\342\200\224resolution'
. Specifically, this command in the script: /Applications/Moonlight.app/Contents/MacOS/Moonlight stream "$_target_computer_ip" "$_moonlight_app_name" —resolution "$_moonlight_resolution" —fps "$_moonlight_fps" &>/dev/null & executes in the shell as: /Applications/Moonlight.app/Contents/MacOS/Moonlight stream 192.168.1.30 mstsc.exe $'\342\200\224resolution' 1920x1024 $'\342\200\224fps' 30 I've tried escaping the hyphen as \-, but that just changes the output to
$'?\200\224
. What am I doing wrong? Here's the full script:
#!/bin/bash
set -x

_target_computer_ip='192.168.1.30'
_target_computer_subnet='192.168.1.255'
_target_computer_mac='2C:F0:5D:27:7C:95'

_moonlight_app_name='mstsc.exe'
_moonlight_resolution='1920x1080'
_moonlight_fps='30'

if ping -c 1 -W 1 "$_target_computer_ip"; then
  echo "is alive"
else
  echo "nope"
  wakeonlan -i $_target_computer_subnet $_target_computer_mac
fi

/Applications/Moonlight.app/Contents/MacOS/Moonlight stream "$_target_computer_ip" "$_moonlight_app_name" —resolution "$_moonlight_resolution" —fps "$_moonlight_fps" &>/dev/null &
And the full command output:
Fayes-MBP:Shell Scripts rain$ ./check_and_wake_pc.sh 
+ _target_computer_ip=192.168.1.30
+ _target_computer_subnet=192.168.1.255
+ _target_computer_mac=2C:F0:5D:27:7C:95
+ _moonlight_app_name=mstsc.exe
+ _moonlight_resolution=1920x1080
+ _moonlight_fps=30
+ echo 192.168.1.30
192.168.1.30
+ ping -c 1 -W 1 192.168.1.30
PING 192.168.1.30 (192.168.1.30): 56 data bytes

--- 192.168.1.30 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss, 1 packets out of wait time
round-trip min/avg/max/stddev = 3.701/3.701/3.701/0.000 ms
+ echo 'is alive'
is alive
+ /Applications/Moonlight.app/Contents/MacOS/Moonlight stream 192.168.1.30 mstsc.exe $'?\200\224resolution' 1920x1080 $'?\200\224fps' 30
Asked by DeadBranch (23 rep)
Feb 17, 2021, 04:26 PM
Last activity: Feb 17, 2021, 09:08 PM