Re: OT: bash () bei variablen

Florian Philipp <[email protected]>
Newsgroups gmane.linux.gentoo.user.german
Message-ID <[email protected]>
Am 08.01.2013 00:05, schrieb jens wefer:
> Am Mon, 07 Jan 2013 07:22:25 +0100
> schrieb Florian Philipp <[email protected]>:
> 
>> Am 07.01.2013 02:27, schrieb jens wefer:
>>>
>>> [...]
>>>
>>
>> `ip=($ip_neu)` erzeugt ein Array ip. `$ip` gibt dir den ersten
>> Eintrag, also genauso wie `${ip[0]}`. Weil du `$ip_neu` nicht escaped
>> hast (`ip=("$ip_neu")`), ist jeder Eintrag whitespace-terminiert.
>>
>> --
>> Florian
> 
> echo ${#ip_neu[@]}   gibt 1 aus, also nur 1 element
> ip=${ip_neu[0]}      gibt mir alles im test 1219 zeichen
> ip=($ip_neu)         gibt 1.ip (getrennt durch space zur 2.
> so wie ich dich verstanden hab muesste ${ip_neu[0]} mir auch doie erste
> ip geben, tut es aber nicht.
> 
> bye, jens.
> 

Nicht wirklich. Bash hat zwar eine implizite Konvertierung von einfachen
zu Array-Variablen, aber die Konvertierung ist äquivalent zu
`ip=("$ip_neu")`, nicht `ip=($ip_neu)`.

BTW: Eine Alternative zum Splitten wäre folgendes:
ip=${ip_neu%%[$'\t'$'\n'' ']*}

Entfernt alles ab dem ersten Tabulator, Zeilenumbruch oder Leerzeichen
und speichert das Ergebnis in ip.

-- Florian Philipp
signature.asc (application/pgp-signature, 262 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlDsHW0ACgkQqs4uOUlOuU/OhgCeKaZ9uTbbptkzQiFIcqIfpr3b
qKcAn1Au88djvNJZai3Z2kBexMKzMZMw
=Gupa
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.