Jump to content

Escape single quotes in run script/script filter


tsf

Recommended Posts

Quite a lot of the scripts I run in Alfred involve handling multiple files (i.e. {query} is a list of tab-separated files). Without some relatively complex code (bash doesn't make it easy) that obfuscates the purpose of the script, they all break with files containing apostrophes. It would be very useful if there were an option to escape single quotes, like you can with double quotes.

Link to comment
Share on other sites

Quite a lot of the scripts I run in Alfred involve handling multiple files (i.e. {query} is a list of tab-separated files). Without some relatively complex code (bash doesn't make it easy) that obfuscates the purpose of the script, they all break with files containing apostrophes. It would be very useful if there were an option to escape single quotes, like you can with double quotes.

 

Would the following code not be sufficient? This will code will split the string base on a tab (alfred's delimiter) and create an array of the file names. It even works with file names that contain single quotes.

query="~/Downloads/file1.txt		~/Downloads/file2.txt	~/Downloads/file3.txt"
IFS="	" read -ra files <<< "$query"
for file in ${files[@]}; do
	echo $file
done
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...