From owner-freebsd-questions@FreeBSD.ORG Tue Feb 16 18:31:49 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7B03A1065670 for ; Tue, 16 Feb 2010 18:31:49 +0000 (UTC) (envelope-from mailnull@mips.inka.de) Received: from mail-in-01.arcor-online.net (mail-in-01.arcor-online.net [151.189.21.41]) by mx1.freebsd.org (Postfix) with ESMTP id 2C8CD8FC08 for ; Tue, 16 Feb 2010 18:31:48 +0000 (UTC) Received: from mail-in-04-z2.arcor-online.net (mail-in-04-z2.arcor-online.net [151.189.8.16]) by mx.arcor.de (Postfix) with ESMTP id ADB99332772 for ; Tue, 16 Feb 2010 19:31:47 +0100 (CET) Received: from mail-in-02.arcor-online.net (mail-in-02.arcor-online.net [151.189.21.42]) by mail-in-04-z2.arcor-online.net (Postfix) with ESMTP id A4E1CAC158 for ; Tue, 16 Feb 2010 19:31:47 +0100 (CET) Received: from lorvorc.mips.inka.de (dslb-094-217-108-223.pools.arcor-ip.net [94.217.108.223]) by mail-in-02.arcor-online.net (Postfix) with ESMTPS id 6B3733FE046 for ; Tue, 16 Feb 2010 19:31:47 +0100 (CET) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-02.arcor-online.net 6B3733FE046 Received: from lorvorc.mips.inka.de (localhost [127.0.0.1]) by lorvorc.mips.inka.de (8.14.4/8.14.3) with ESMTP id o1GIVkx1090043 for ; Tue, 16 Feb 2010 19:31:46 +0100 (CET) (envelope-from mailnull@lorvorc.mips.inka.de) Received: (from mailnull@localhost) by lorvorc.mips.inka.de (8.14.4/8.14.4/Submit) id o1GIVk0U090042 for freebsd-questions@freebsd.org; Tue, 16 Feb 2010 19:31:46 +0100 (CET) (envelope-from mailnull) From: naddy@mips.inka.de (Christian Weisgerber) Date: Tue, 16 Feb 2010 18:31:46 +0000 (UTC) Message-ID: References: <560f92641002142207w7eade79fr6a4f40ae5b92f4b9@mail.gmail.com> <560f92641002151216l6b8e97f4u886ac8e3b86d231e@mail.gmail.com> Originator: naddy@mips.inka.de (Christian Weisgerber) To: freebsd-questions@freebsd.org Subject: Re: simple (and stupid) shell scripting question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Feb 2010 18:31:49 -0000 Nerius Landys wrote: > Is there a function, or command line utility, to "escape" a string, > making it suitable to be input on the command line? For example, this > "escape" utility would take a input of "te st" and create an output of > "te\ st". Other things such as quotes and single quotes would be > handled as well. You can use something like this: sed 's/[^A-Za-z_0-9]/\\&/' Perl has a quotemeta() function and \Q escape sequence for this purpose, e.g.: $ perl -e '$_="te st"; print "\Q$_\E\n"' te\ st -- Christian "naddy" Weisgerber naddy@mips.inka.de