Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: misc.striptrailingblanks - Function Up: misc - Tool Previous: misc.shellcmd - Function


misc.escapespecial - Function



Package utility
Module misc
Tool misc


escape characters in a string special to the shell


Synopsis
escapespecial(string)


Description
This simply replaces the characters *, #, (, ), and |, by the sequences \* - \|, respectively. This is mainly used on strings that are to be passed to the shell. In a compromise between speed and completeness, this is only a subset of all possible significant characters, but it covers the most commonly problematic cases. There is no escape mechanism to avoid the filtering. This uses the builtin regex substitution capabilities of Glish.



Arguments

string   String
    Allowed: String


Returns
String


Example
- dms.escapespecial('abc def ghi jkl mno')
abc def ghi jkl mno 
- dms.escapespecial('a#c d*f g(i j)l m|o') 
a\#c d\*f g\(i j\)l m\|o 
-
+ files := shell('ls -1 A*foo')                                   
- files
A*foo Anotherfoo 
-
+ for (f in files) { print shell(spaste('ls -l ',f)) }                
-rw-rw-r--   1 dbriggs  visitor        5 Dec 19 18:02 A*foo 
-rw-rw-r--   1 dbriggs  visitor        4 Dec 19 18:16 Anotherfoo
-rw-rw-r--   1 dbriggs  visitor        4 Dec 19 18:16 Anotherfoo
-
+ for (f in files) { print shell(spaste('ls -l ',dms.escapespecial(f))) }
-rw-rw-r--   1 dbriggs  visitor        5 Dec 19 18:02 A*foo
-rw-rw-r--   1 dbriggs  visitor        4 Dec 19 18:16 Anotherfoo
The * in the filename, which we don't know about a priori, has confused the shell. This is cured simply by wrapping all unknown strings in dms.escapespecial() before passing them to the shell.





next up previous contents index
Next: misc.striptrailingblanks - Function Up: misc - Tool Previous: misc.shellcmd - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15