Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Feb 2010 12:16:00 -0800
From:      Nerius Landys <nlandys@gmail.com>
To:        Christian Weisgerber <naddy@mips.inka.de>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: simple (and stupid) shell scripting question
Message-ID:  <560f92641002151216l6b8e97f4u886ac8e3b86d231e@mail.gmail.com>
In-Reply-To: <hlbmrs$1fc8$1@lorvorc.mips.inka.de>
References:  <560f92641002142207w7eade79fr6a4f40ae5b92f4b9@mail.gmail.com> <hlbmrs$1fc8$1@lorvorc.mips.inka.de>

next in thread | previous in thread | raw e-mail | index | archive | help
>> #!/bin/sh
>>
>> DIRNAME=3D"`dirname \"$0\"`"
>> cd "$DIRNAME"
>> SCRIPTDIR=3D"`pwd`"
>>
>> What if I got rid of extra double quotes? =A0Like this:
>>
>> DIRNAME=3D`dirname \"$0\"`
>> cd "$DIRNAME"
>> SCRIPTDIR=3D`pwd`
>
> That is perfectly fine. =A0Word-splitting and filename expansion are
> not performed for variable assignments. =A0Also immune is the expression
> after "case", so this is always fine:
>
> =A0case $FOO in ...

Since you guys have been so helpful I thought I'd ask one more question.

Let's say I have a script named "te st" (yes, with a space in the filename)=
.
The contents of this script are:

#!/bin/sh
if [ $# -ne 2 ]; then
    echo 1>&2 "One argument expected.  Example usage:"
    echo 1>&2 "  `basename \"${0}\"` 64.156.192.169 cheaters"
    exit 1
fi

When executed with no arguments, this script would print something like so:

nlandys@daffy<zsh># ./te\ st
One argument expected.  Example usage:
  te st 64.156.192.169 cheaters
nlandys@daffy<zsh>#

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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?560f92641002151216l6b8e97f4u886ac8e3b86d231e>