ALT Linux sysadmins discussion
 help / color / mirror / Atom feed
From: Michael Shigorin <mike@osdn.org.ua>
To: sysadmins@lists.altlinux.org
Subject: Re: [Sysadmins] bash | read
Date: Fri, 18 Jan 2008 11:44:38 +0200
Message-ID: <20080118094438.GT7309@osdn.org.ua> (raw)
In-Reply-To: <20080117194344.GN7275@osdn.org.ua>

On Thu, Jan 17, 2008 at 09:43:44PM +0200, Michael Shigorin wrote:
> При этом что-нить вроде такого работает, как ожидается:
> | while read first second junk; do
> 	# something with $first (first IFS-delimited word)
> 	# ...and with $second too...
> 	# the rest of the line goes to $junk
> done
> 
> -- именно потому, что тут-то всё выполняется в одном сабшелле ;)

При этом вынуть из него что-то, ессно, можно через stdout
сотоварищи или файлики.

hiddenman@ рассказал вот ещё что:

<hiddenman> re на твое сообщение в sysadmins@ про bash
<hiddenman> я когда etcnet патчил, столкнулся с этой и другими проблемами
<hiddenman> есть магический способ, почему-то мало где описан
<hiddenman> #!/bin/bash
A='test'
echo $A |
while read B; do
   C=$B
   echo "C in the subshell1 is $C"
done
echo "C out of the subshell1 is $C"

while read D; do
   E=$D
   echo "E in the subshell2 is $E"
done < <(echo "$A")
echo "E out of the subshell2 is $E"

<hiddenman> во втором варианте это не subshell. в результате мы снаруж имеем то, что изменили в этом while. да и работает он много быстрее, проверял
<hiddenman> такая вот magic :)
<hiddenman> можешь туда кинуть пока. я через nntp читаю, от рассылок отписался, но писать еще не пробовал через gmane.org :)
<hiddenman> упс, зачем я лишнего наделал....вот исправленный вариант:
<hiddenman> а, не , все правильно. внутри нужно присваивание сделать, переменные на время while read не экспортируются
<hiddenman> то бишь, вариант:
<hiddenman> #!/bin/bash
A='test'
echo $A |
while read B; do
   echo "B in the subshell1 is $B"
done
echo "B out of the subshell1 is $B"

while read C; do
   echo "C in the subshell2 is $C"
done < <(echo "$A")
echo "C out of the subshell2 is $C"

<hiddenman> работать не будет

-- 
 ---- WBR, Michael Shigorin <mike@altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/


      reply	other threads:[~2008-01-18  9:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-17 19:43 Michael Shigorin
2008-01-18  9:44 ` Michael Shigorin [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=20080118094438.GT7309@osdn.org.ua \
    --to=mike@osdn.org.ua \
    --cc=shigorin@gmail.com \
    --cc=sysadmins@lists.altlinux.org \
    /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 sysadmins discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/sysadmins/0 sysadmins/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 sysadmins sysadmins/ http://lore.altlinux.org/sysadmins \
		sysadmins@lists.altlinux.org sysadmins@lists.altlinux.ru sysadmins@lists.altlinux.com
	public-inbox-index sysadmins

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


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