I have a command I need to run in a bash script that takes the output of a previous command and inserts it into a new command.
So for example:
VARIABLE=$(cat "file.txt" | grep "text")
Then use that variable in another command:
mycommand -p "$VARIABLE"
The catch is the $VARIABLE will always contain special characters, namely $ and / which I need so I need to single quote that so the special characters are taken literal.
I've tried \""$VARIABLE"\"
which didn't work.
What I'm trying to accomplish is I need to grab a line out of a text file that includes my search term, which is unique and only one line will have it.
I then need to input that line (well, half of it, I'm also cutting the line and using the second half) into another command. I am able to successfully grab the text I need which I verified by echoing the variable afterwards. The problem is the variable contains $ and \ that are being interpreted as special characters.
For example:
my command -p $345$randomtext\.moretext
Without single quoting the variable it is interpreted which throws errors.