* [Comm] Bash string for escape symbols in string
@ 2005-02-21 11:30 Vitaly Ostanin
2005-02-21 12:14 ` Dmitry V. Levin
0 siblings, 1 reply; 5+ messages in thread
From: Vitaly Ostanin @ 2005-02-21 11:30 UTC (permalink / raw)
To: community
[-- Attachment #1: Type: text/plain, Size: 669 bytes --]
Здравствуйте.
Подскажите, pls, чем из coreutils из функций bash можно
экранировать спец. символы в строке? Экранировать нужно именно с
помощью \, т.к. есть подозрение, что передачу списка имён файлов
с пробелами из меню mc в
growisofs ... graft-points list_of_files
с помощью кавычек не сделать.
По крайней мере, такая конструкция с разными вариантами кавычек у
меня не заработала - ищется каталог из первого слова первого
каталога.
GRAFT_OPT=
for i in %t
do
GRAFT_OPT=$GRAFT_OPT\ /$i=$i
done
growisofs -Z /dev/cdrecorder -R -jcharset cp1251
-graft-points "$GRAFT_OPT"
--
Regards, Vyt
mailto: vyt@vzljot.ru
JID: vyt@vzljot.ru
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Comm] Bash string for escape symbols in string
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
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry V. Levin @ 2005-02-21 12:14 UTC (permalink / raw)
To: ALT Linux general discussion list
[-- Attachment #1: Type: text/plain, Size: 247 bytes --]
Hi,
On Mon, Feb 21, 2005 at 02:30:48PM +0300, Vitaly Ostanin wrote:
> Подскажите, pls, чем из coreutils из функций bash можно
> экранировать спец. символы в строке?
Условие "из coreutils" обязательно? А то я бы выбрал sed.
--
ldv
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Comm] Re: Bash string for escape symbols in string
2005-02-21 12:14 ` Dmitry V. Levin
@ 2005-02-21 12:21 ` Vitaly Ostanin
2005-02-21 13:32 ` [Comm] Re: growisofs (was: Bash string for escape symbols in string) Vitaly Ostanin
0 siblings, 1 reply; 5+ messages in thread
From: Vitaly Ostanin @ 2005-02-21 12:21 UTC (permalink / raw)
To: community
[-- Attachment #1: Type: text/plain, Size: 443 bytes --]
Dmitry V. Levin пишет:
> Hi,
>
> On Mon, Feb 21, 2005 at 02:30:48PM +0300, Vitaly Ostanin wrote:
>
>>Подскажите, pls, чем из coreutils из функций bash можно
>>экранировать спец. символы в строке?
>
> Условие "из coreutils" обязательно?
Нет, это я пытался по-умному выразить доступность и
распространённость инструмента :)
> А то я бы выбрал sed.
Спасибо, попробую.
<skipped/>
--
Regards, Vyt
mailto: vyt@vzljot.ru
JID: vyt@vzljot.ru
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Comm] Re: growisofs (was: Bash string for escape symbols in string)
2005-02-21 12:21 ` [Comm] " Vitaly Ostanin
@ 2005-02-21 13:32 ` Vitaly Ostanin
2005-02-21 22:28 ` [Comm] quotation in shell Dmitry V. Levin
0 siblings, 1 reply; 5+ messages in thread
From: Vitaly Ostanin @ 2005-02-21 13:32 UTC (permalink / raw)
To: community
[-- Attachment #1: Type: text/plain, Size: 2544 bytes --]
Vitaly Ostanin пишет:
> Dmitry V. Levin пишет:
>
>>Hi,
>>
>>On Mon, Feb 21, 2005 at 02:30:48PM +0300, Vitaly Ostanin wrote:
>>
>>
>>>Подскажите, pls, чем из coreutils из функций bash можно
>>>экранировать спец. символы в строке?
>>
>>Условие "из coreutils" обязательно?
>
> Нет, это я пытался по-умному выразить доступность и
> распространённость инструмента :)
>
>>А то я бы выбрал sed.
>
> Спасибо, попробую.
Попробовал - не получилось, и это утешает - неужели может быть
разница в способах экранирования? Скажите, у кого из нас ошибка в
ДНК - у меня или у growisofs ?
$ cat burn-dvd-files.sh
GRAFT_OPT=
for i in "$@"
do
if [ "$GRAFT_OPT"x != x ]; then GRAFT_OPT=$GRAFT_OPT\ ; fi
GRAFT_OPT=$GRAFT_OPT\"/$i\"=\"$i\"
done
#echo $GRAFT_OPT
growisofs -Z /dev/cdrecorder -R -jcharset cp1251 -graft-points
$GRAFT_OPT
$ ./burn-dvd-files.sh Тестовый\ каталог/ Снова\ тестовый\ каталог/
WARNING: /dev/cdrecorder already carries isofs!
About to execute 'mkisofs -R -jcharset cp1251 -graft-points
"/Тестовый каталог/"="Тестовый каталог/" "/Снова тестовый
каталог/"="Снова тестовый каталог/" | builtin_dd
of=/dev/cdrecorder obs=32k seek=0'
mkisofs: No such file or directory. Invalid node - "/Тестовый
:-( write failed: Input/output error
После убирания кавычек из цикла (\"):
$ ./burn-dvd-files.sh Тестовый\ каталог/ Снова\ тестовый\ каталог/
WARNING: /dev/cdrecorder already carries isofs!
About to execute 'mkisofs -R -jcharset cp1251 -graft-points
/Тестовый каталог/=Тестовый каталог/ /Снова тестовый
каталог/=Снова тестовый каталог/ | builtin_dd of=/dev/cdrecorder
obs=32k seek=0'
mkisofs: No such file or directory. Invalid node - /Тестовый
:-( write failed: Input/output error
После добавления кавычек в запуск growisofs:
growisofs -Z /dev/cdrecorder -R -jcharset cp1251 -graft-points
"$GRAFT_OPT"
$ ./burn-dvd-files.sh Тестовый\ каталог/ Снова\ тестовый\ каталог/
WARNING: /dev/cdrecorder already carries isofs!
About to execute 'mkisofs -R -jcharset cp1251 -graft-points
/Тестовый каталог/=Тестовый каталог/ /Снова тестовый
каталог/=Снова тестовый каталог/ | builtin_dd of=/dev/cdrecorder
obs=32k seek=0'
mkisofs: No such file or directory. Invalid node - Тестовый
каталог/ /Снова тестовый каталог/=Снова тестовый каталог/
:-( write failed: Input/output error
При этом скрипт такого содержания пишет нормально:
growisofs -Z /dev/cdrecorder -R -jcharset cp1251 -graft-points
"/Тестовый каталог=Тестовый каталог" "/Снова тестовый
каталог=Снова тестовый каталог"
--
Regards, Vyt
mailto: vyt@vzljot.ru
JID: vyt@vzljot.ru
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Comm] quotation in shell
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
0 siblings, 0 replies; 5+ messages in thread
From: Dmitry V. Levin @ 2005-02-21 22:28 UTC (permalink / raw)
To: ALT Linux general discussion list
[-- 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 --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-02-21 22:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [Comm] quotation in shell Dmitry V. Levin
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