Re: OT: bash () bei variablen

Florian Philipp <[email protected]>
Newsgroups gmane.linux.gentoo.user.german
Message-ID <[email protected]>
Am 07.01.2013 02:27, schrieb jens wefer:
> hey,
> 
> ip_neu=`cat $TMPDIR/$TMPFILE | grep -Eo
> '([0-9]{1,3}\.){3}[0-9]{1,3}'` laenge=${#untestedip}
> 
> damit hol ich ip's aus ner datei, da kommt dann einer oder auch meherer
> getrennt mit space oder return.
> ich will nur die erste, wenn mehr sind greif ich mir die erste als
> substring.
> 
> klappt alles wie gewuenscht.
> 
> nun hab ich entdeckt das:
> ip1=($ip_neu)
> mir genau die gewuenschte 1.ip gibt.
> 
> hab gesucht und nix dazu in der doku gefunden, bzw. steht da was von
> subshell, etc..
> hat jmd nen tip was die klappern bei variablen bewirkt?
> 
> bye, jens.
> 

`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
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/

iEYEARECAAYFAlDqaaYACgkQqs4uOUlOuU+TrACdHMJapn+8Cc3SQFFt5tWOVg/R
wQkAnRSNO96BNQE/rviZLqORg+HhpXHA
=DDio
-----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.