I have a question about nested double quotes. Any help is appreciated.
Here are my commands on Mac OS.
# string="Ethernet \"USB Ethernet\" \"Bluetooth DUN\" AirPort FireWire \"Bluetooth PAN\""
# echo $string
Ethernet "USB Ethernet" "Bluetooth DUN" AirPort FireWire "Bluetooth PAN"
# networksetup -ordernetworkservices $string - This gives error.
The networksetup command requires quote around service name that has space in it.
But when shell expands the $string that has nested quotes, it treats the string that has quote around it as two separate words. In this case, "USB Ethernet" becomes 'USB' 'Ethernet'. What I really want is "USB Ethernet".
' ' = remove special characters special role = wysewyg. Not usable with variables.
" " = remove special characters special role except $ and \ = variable using
string='Ethernet "USB Ethernet" "Bluetooth DUN" AirPort FireWire "Bluetooth PAN"'
# echo $string is not same as
echo "$string"
Ethernet "USB Ethernet" "Bluetooth DUN" AirPort FireWire "Bluetooth PAN"
networksetup -ordernetworkservices "$string" # one args for option
# networksetup -ordernetworkservices $string # is not same, now we have lot of args
change the quote does not work.
$ cat data
Ethernet "USB Ethernet" "Bluetooth DUN" AirPort FireWire "Bluetooth PAN"
networksetup -ordernetworkservices `cat data`
++ cat data
+ networksetup -ordernetworkservices Ethernet '"USB' 'Ethernet"' '"Bluetooth' 'DUN"' AirPort FireWire '"Bluetooth' 'PAN"'
Wrong number of network services... No changes have been made.
Note: Quotes must be used around service names which contain spaces (ie. "Built-in Ethernet").
** Error: The parameters were not valid.
The shell puts single quote around each word that inside double quote.
'"USB' 'Ethernet"'
how to get rid of the single quote ?