Auto escape script to escape special chars in script args

This is a bit off the wall, but I often need to run scripts where there are argument values that contain special characters.

For example,

$ ./process.exe -t M -N -o temp.mol.s -i ../molfiles/N,N\',N\'\'-trimethylbis\(hexamethylene\)triamine.mol && sfile_space_to_tab.sh  temp.mol.s temp.s

It is tedious to manually escape everything and auto complete does not always solve this problem.

I was wondering if I could write a script and pass my entire command string to the script. I would keep the script in a path directory and the script would escape chars where necessary and then pass the string along to bash. The syntax could look like,

$ auto_escape ./process.exe -t M -N -o temp.mol.s -i ../molfiles/N,N\',N\'\'-trimethylbis\(hexamethylene\)triamine.mol && sfile_space_to_tab.sh  temp.mol.s temp.s

I think I could do the substitutions in sed, but I'm not sure how to capture everything after auto_escape and pass that to sed.

A bigger issue is how to keep the notion of pwd in tact. The pwd locations of process.exe and auto_escape will be different, so when bash recieves the string from the auto_escape script, I'm not sure how I could get bash to properly interpret ./, ../ etc, in terms of the original script location.

Thanks for the advice,

LMHmedchem

This is a misunderstanding of the problem... It is not process.exe that requires all this quoting, it's the shell that requires all this quoting. Feeding it into any other program would have the same problem.

However, the shell has an easy way to do this. May I suggest the much simpler facility of double quotes? The only things you will need to escape inside them are " ` $.

./process.exe -t M -N -o temp.mol.s -i "../molfiles/N,N',N''-trimethylbis(hexamethylene)triamine.mol" && sfile_space_to_tab.sh  temp.mol.s temp.s