Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #247290

Re: disable IPv6 debian

From Greg Wooledge <greg@wooledge.org>
Newsgroups linux.debian.user
Subject Re: disable IPv6 debian
Date 2022-04-16 15:00 +0200
Message-ID <EcQbT-9809-1@gated-at.bofh.it> (permalink)
References (5 earlier) <EcENr-915z-3@gated-at.bofh.it> <EcFJv-91D1-3@gated-at.bofh.it> <EcJWN-94q5-1@gated-at.bofh.it> <EcKg9-94wf-25@gated-at.bofh.it> <EcLYB-95yy-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sat, Apr 16, 2022 at 04:20:15PM +0800, wilson wrote:
> does bash shell have the list/array concept?

Bash has indexed arrays (since forever) and associative arrays (in
version 4.0 and above).

> ~$ list="1 2 3 4"
> 
> ~$ for i in $list; do echo $i; done
> 1
> 2
> 3
> 4
> 
> is this a list access?

That's a string, and an abuse of word-splitting.  It's a common
anti-pattern used in sh scripts, because sh doesn't have arrays or lists.
It "works" in this simple case, and in many other simple cases, where
the "list" elements are known-in-advance words that don't contain any
whitespace or globbing characters (and can't be the empty string).

It completely fails if the list elements contain any of those things.
Most notably, when the list elements are filenames, this approach is
doomed.

Here's how you would do it correctly in bash:

  list=(1 '' 2 'two and a half' 3 '3.14*' 4)

  for i in "${list[@]}"; do echo "<$i>"; done

The for loop can mostly be replaced by a single printf:

  printf '<%s>\n' "${list[@]}"

But there is one difference: if the array is empty (has zero elements),
the printf will still print one time, with an empty string as the
argument.  The for loop will not print anything at all.

See also:

https://mywiki.wooledge.org/BashGuide
https://mywiki.wooledge.org/BashFAQ/005

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-15 13:50 +0200
  Re: disable IPv6 debian 황병희 <soyeomul@doraji.xyz> - 2022-04-15 14:00 +0200
    Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-15 14:30 +0200
      Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-15 17:00 +0200
        Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-15 18:00 +0200
          Re: disable IPv6 debian Tim Woodall <debianuser@woodall.me.uk> - 2022-04-15 18:10 +0200
        Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 02:10 +0200
          Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-16 02:20 +0200
            Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 02:30 +0200
              Re: disable IPv6 debian Charles Curley <charlescurley@charlescurley.com> - 2022-04-16 02:40 +0200
              Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-16 02:50 +0200
                Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 03:10 +0200
                Re: disable IPv6 debian The Wanderer <wanderer@fastmail.fm> - 2022-04-16 03:50 +0200
                Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 04:10 +0200
                Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-16 05:00 +0200
                Re: disable IPv6 debian The Wanderer <wanderer@fastmail.fm> - 2022-04-16 14:10 +0200
                Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-16 15:10 +0200
                Re: disable IPv6 debian David Wright <deblis@lionunicorn.co.uk> - 2022-04-16 18:10 +0200
                Re: disable IPv6 debian <tomas@tuxteam.de> - 2022-04-16 08:20 +0200
                Re: disable IPv6 debian Tim Woodall <debianuser@woodall.me.uk> - 2022-04-16 08:40 +0200
                Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 10:30 +0200
                Re: disable IPv6 debian David <bouncingcats@gmail.com> - 2022-04-16 10:50 +0200
                Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-16 15:00 +0200
            Re: disable IPv6 debian Michael Stone <mstone@debian.org> - 2022-04-16 20:00 +0200
          Re: disable IPv6 debian <tomas@tuxteam.de> - 2022-04-16 08:20 +0200
      Re: disable IPv6 debian Chuck Zmudzinski <brchuckz@netscape.net> - 2022-04-15 19:40 +0200
      Re: disable IPv6 debian Andy Smith <andy@strugglers.net> - 2022-04-16 01:00 +0200
        Re: disable IPv6 debian didar <nosferatu@purlo.in> - 2022-04-16 07:10 +0200
          Re: disable IPv6 debian Andy Smith <andy@strugglers.net> - 2022-04-16 11:50 +0200
  Re: disable IPv6 debian Reco <recoverym4n@enotuniq.net> - 2022-04-15 14:30 +0200
    Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-15 14:40 +0200
      Re: disable IPv6 debian Erwan David <erwan@rail.eu.org> - 2022-04-15 16:00 +0200
        Re: disable IPv6 debian Jeremy Ardley <jeremy@ardley.org> - 2022-04-15 16:20 +0200
      Re: disable IPv6 debian Reco <recoverym4n@enotuniq.net> - 2022-04-15 16:20 +0200
  Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 02:20 +0200
  Re: disable IPv6 debian Ash Joubert <ash@transient.nz> - 2022-04-16 02:20 +0200

csiph-web