philipmorgan Posted December 30, 2014 Share Posted December 30, 2014 (edited) I'm trying to modify the AppendText2File workflow so that if the text to be appended has a single quote inside it the workflow doesn't break. Here's the relevant portion of the workflow: dt=`date` ## append to the original file echo "* "$dt" -- "{query} >> $original What do I do to strip out single quotes (or replace them with something bash/Alfred doesn't hate)? Edited December 30, 2014 by philipmorgan Link to comment
vitor Posted December 30, 2014 Share Posted December 30, 2014 A possible solution (haven’t looked into the workflow itself) would be to surround {query} itself in double quotes (single quotes will have no effect there), and espace the options that could be problematic. dt="$(date)" ## append to the original file echo "* ${dt} -- {query}" >> "${original}" philipmorgan 1 Link to comment
philipmorgan Posted December 30, 2014 Author Share Posted December 30, 2014 That worked!!! Thank you Vitor! Here's the new syntax (with escaping turned on in Alfred as you suggested): echo "* {query} ("$dt")" >> $original Link to comment
vitor Posted December 30, 2014 Share Posted December 30, 2014 You don’t need to interrupt the double quotes, as they allow for string interpolation. What this means is echo "* {query} ($dt)" >> $original works just as well (but echo "* {query} (${dt})" >> "${original}" is how I’d write it). Link to comment
philipmorgan Posted December 30, 2014 Author Share Posted December 30, 2014 Thanks Vitor, I went with your enhanced syntax. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now