ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: "Dmitry V. Levin" <ldv@altlinux.org>
To: ALT Linux general discussion list <community@altlinux.ru>
Subject: Re: [Comm] quotation in shell
Date: Tue, 22 Feb 2005 01:28:47 +0300
Message-ID: <20050221222847.GA32710@basalt.office.altlinux.org> (raw)
In-Reply-To: <4219E2DE.90801@vzljot.ru>

[-- Attachment #1: Type: text/plain, Size: 1349 bytes --]

On Mon, Feb 21, 2005 at 04:32:14PM +0300, Vitaly Ostanin wrote:
> >>>Подскажите, pls, чем из coreutils из функций bash можно
> >>>экранировать спец. символы в строке?
> >>Условие "из coreutils" обязательно?
> >Нет, это я пытался по-умному выразить доступность и
> >распространённость инструмента :)
> >>А то я бы выбрал sed.
> >Спасибо, попробую.
> Попробовал - не получилось, и это утешает - неужели может быть
> разница в способах экранирования? Скажите, у кого из нас ошибка в
> ДНК - у меня или у growisofs ?

К сожалению, до growisofs ваша ошибка просто не дошла.

Дело в том, что аргументы запускаемой команды формирует shell.
Как бы вы не экранировали спецсимволы внутри переменной, shell не
догадается, что вы занимались экранированием.

Если вы пишете
$ cmd $var
то shell применит к содержимому переменной var "word splitting" и
"pathname expansion".

Если вы пишете
$ cmd "$var"
то shell просто отдаст значение переменной var в том виде, в каком оно
есть.

Если вы хотите добиться чего-то отличного от вышеприведённых вариантов,
то следует вспомнить про eval.

Например, попробуйте запускать нижеприведённый скрипт с разными
параметрами:

args=
for i in "$@"; do
	args="$args \"$(printf %s "/$i=$i" |sed -e 's/[\`"$]/\\&/g')\""
done
eval env -i strace -e trace=execve /bin/true "$args"


-- 
ldv

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2005-02-21 22:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-21 11:30 [Comm] Bash string for escape symbols in string Vitaly Ostanin
2005-02-21 12:14 ` Dmitry V. Levin
2005-02-21 12:21   ` [Comm] " Vitaly Ostanin
2005-02-21 13:32     ` [Comm] Re: growisofs (was: Bash string for escape symbols in string) Vitaly Ostanin
2005-02-21 22:28       ` Dmitry V. Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050221222847.GA32710@basalt.office.altlinux.org \
    --to=ldv@altlinux.org \
    --cc=community@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git