Function: te-quote-arg-for-sh

te-quote-arg-for-sh is a byte-compiled function defined in terminal.el.gz.

Signature

(te-quote-arg-for-sh STRING)

Source Code

;; Defined in /usr/src/emacs/lisp/obsolete/terminal.el.gz
;;;; what a complete loss

(defun te-quote-arg-for-sh (string)
  (cond ((string-match "\\`[-a-zA-Z0-9+=_.@/:]+\\'"
		       string)
	 string)
	((not (string-search "$" string))
	 ;; "[\"\\]" are special to sh and the lisp reader in the same way
	 (prin1-to-string string))
	(t
	 (let ((harder "")
	       (start 0)
	       (end 0))
	   (while (cond ((>= start (length string))
			 nil)
			;; this is the set of chars magic with "..." in `sh'
			((setq end (string-match "[\"\\$]"
						 string start))
			 t)
			(t (setq harder (concat harder
						(substring string start)))
			   nil))
	     (setq harder (concat harder (substring string start end)
                                  ;; Can't use ?\\ since `concat'
                                  ;; unfortunately does prin1-to-string
                                  ;; on fixna.  Amazing.
				  "\\"
				  (substring string
					     end
					     (1+ end)))
		   start (1+ end)))
	   (concat "\"" harder "\"")))))