I'm fairly new to Bash so please forgive me, but I'm building a Bash script that can accept a user input command that can have a lot of switches. I need to write a function that pulls specific data from that user provided command.
I can't seem to find a way to pull each word after "-mode" and push it into an array or list of some sort.
Here is an example of what the user input command might look like:
/home/custom/function/that/accepts/a/billion/switches random_info random_info2 -worker vendor_schmo -switch_one -anotherOne -more_switches -optionTwo -mode FOO -mode BAR -mode BAZ -mode BAG -mode DAT -mode RAR
I've tried fiddling with awk -F "-mode" '{ print $1 }' and that didn't work. Any advice would be much appreciated!!
Here is the snippet from the script that pulls this info:
manualRunMain(){
local command
manualRunHeaderPrint
echo
echo
echo
echo
lineBreakPrint
read -p "Enter your command here: " command
sleep .25
manualRun "$command"
}
manualRun(){
manualRunHeaderPrint
jobRunSubHeaderPrint
pullModeNames "$1"
}
pullModeNames(){
}
-foo "bar baz"and-foo bar baz).array=( $string ); that said, it is a question with accepted, canonical answers already present in our knowledge base).