Nevermind, found it. Thanks for the suggestion @seaside, but I found a bash integrated function (faster to call these than sed)
Code: Select all
CFG1="`echo "$CHOOSER2" | grep WORD1 | sed 's/WORD1=//' | sed 's/\"//'`"
CFG1=${CFG1%\"}
First echo's out the value, sends it to grep to pull only WORD1, strips WORD1= (gets rid of that first =, sed's the first ", then does a end-strip of the last ".
Provided gtkdialog doesn't change its behavior for passing back values... this should work. I'd honestly be happy if there was a way to do it without sed...
And I've found that I can do it with that same expansion.
I'm building this as a complex function (well, not THAT complex) but so I can just remember what is happening without quite as hard to read...?
well hell, I got nearly everything I wanted... but I use an eval statement to push a value back OUT to the calling argument from a function... and it strips double quotes, and freaks out with single quotes.
Here's the code I have so far...
Code: Select all
function pc_strip () # pc_strip arg1 arg2.
{
# arg1 should be the name of the var to strip with.
# arg2 should be the name of the variable from gtkdialog.
y=\$"$1" # y becomes "$arg1".
x=`eval "expr \"$y\" "` # x becomes value of $arg1, so $x = $arg1.
# finally start our strips.
x=${x#$2=\"} # strip out arg2=" from beginning
x=${x%\"} # strip out " from end
# now to protect any quotes.
echo $x " - that was arg1!"
eval "$1=$x" # push value back onto $arg1
}
Apparently, ${x#$2=\"} says: Take $x, strip out from it the contents of $2 plus = plus ", from teh beginning.
Then, ${x%\"} says "take $x, strip the " from the end"
That gets rid of all the questionables, but if the user passes quotes in their args, unfortunately in that "echo $x " - that was arg1" line, it shows them, but when pushed back onto $arg1 using the eval the quotes get nuked by our good friend eval. How to resolve? I do want to do this with functions, so that the actual text in the script is more legible, and to minimize retyped stuff.