Ubuntun 16.04
Bash 4.4.0
I have lines and lines in a csv file that I can use as variables. Example:
"2013","White Woman","Green Orcas Rolling","Felix"
"2014","White Woman","Green Orcas Rolling","Felix"
"2012","White Woman","Green Orcas Rolling","Felix"
"2011","White Woman","Green Orcas Rolling","Felix"
I want to pass these lines into a bash script that will generate a complete url.
Example: bash scriptname.sh "2012","White Woman","Green Orcas Rolling","Felix"
I can replace spaces that are within the variables from inside the script. How can I strip the commas that separate the variables being passed to the script, inside the script, before they interact and set themselves.
Here's an example of my script:
#!/bin/bash
year="${1}"
oinker="${2// /%20}"
poinker="${3// /%20}"
loinker="${4// /%20}"
echo "https://mickeyorileysooo.com/sysbuilder.php?bg=2&year=${year}&oinker=${oinker}&poinker=${poinker}&loinker=${loinker}"
Here is the result:
root@0000 ~ # bash scriptname.sh "2012" "White Woman" "Green Orcas Rolling" "Felix"
https://mickeyorileysooo.com/sysbuilder.php?bg=2&year=2012&oinker=White%20Woman&poinker=Green%20Orcas%20Rolling&loinker=Felix
Here is an updated script with guidance from Barmar:
#!/bin/bash
IFS=,
set -- $*
year="${1}"
oinker="${2// /%20}"
poinker="${3// /%20}"
loinker="${4// /%20}"
echo "https://mickeyorileysooo.com/sysbuilder.php?bg=2&year=${year}&oinker=${oinker}&poinker=${poinker}&loinker=${loinker}"
Now I leave the commas on the command line and run the script:
root@0000 ~ # bash scriptname.sh "2012","White Woman","Green Orcas Rolling","Felix"
https://mickeyorileysooo.com/sysbuilder.php?bg=2&year=2012&oinker=White%20Woman&poinker=Green%20Orcas%20Rolling&loinker=Felix
The commas are now gone and the result is perfect!
https://mickeyorileysooo.com/sysbuilder.php?bg=2&year=2012&oinker=White%20Woman&poinker=Green%20Orcas%20Rolling&loinker=Felix