I have the below command that fails when I run it through a bash script but If I copy each echoed statement and paste them in a terminal it works…
networksetup -listallntworkservices | while read line; do networksetup -setautoproxy '"'$line'"' http://etc...
I ideally only want to run the above command for network services that have “Ethernet” or “Wi-fi” in the name.
As I don’t know what are the input of your command :
Try change
'"'$line'"'by"$line"or"'$line'".To avoid shell expansion in the case variable contains spaces always double quote variables when passing an argument to a command.
If double quotes are needed inside variable, this should work:
"\"$line\""To filter lines matching Ethernet or Wi-fi