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


Groups > linux.debian.user > #275409

Re: Shell function & variable usage.

From peter@easthope.ca
Newsgroups linux.debian.user
Subject Re: Shell function & variable usage.
Date 2024-12-08 19:50 +0100
Message-ID <JRuvT-eUmy-5@gated-at.bofh.it> (permalink)
References <JQQ5r-eiDW-13@gated-at.bofh.it> <JQQf7-eiHL-1@gated-at.bofh.it> <JR48q-eriw-11@gated-at.bofh.it> <JR5xv-esh2-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


    From: Greg Wooledge <greg@wooledge.org>
    Date: Sat, 7 Dec 2024 11:08:54 -0500
>     "${exclusions[@]//#/--exclude=}"

In a shell script; correct?

I'm making a shell function declared in .bashrc.  Numerous syntactical 
variations were unsuccessful.  Maybe a simple escape syntax is needed.

Stretched a test out to this.  it works.

Test() { \
  exclusions=( \
  'file' \
  '*.mp3' \
  '*.mp4' );
  echo "exclusions = ${exclusions[@]}";
  n=${#exclusions[@]};
  i=0;
  while [ "$i" -lt "$n" ]; do
    echo ${exclusions[$i]};
    exclusions[$i]="--exclude=${exclusions[$i]}";
    ((i++));
  done;
  echo "i = $i";
  echo "exclusions = ${exclusions[@]}";
}

When I'm happy with Test, will incorporate into the Backup function.

Thanks for the help,                      ... P.

-- 
VoIP:   +1 604 670 0140
work: https://en.wikibooks.org/wiki/User:PeterEasthope

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


Thread

Shell function & variable usage. peter@easthope.ca - 2024-12-07 00:40 +0100
  Re: Shell function & variable usage. Greg Wooledge <greg@wooledge.org> - 2024-12-07 00:50 +0100
    Re: Shell function & variable usage. peter@easthope.ca - 2024-12-07 15:40 +0100
      Re: Shell function & variable usage. Greg Wooledge <greg@wooledge.org> - 2024-12-07 17:10 +0100
        Re: Shell function & variable usage. peter@easthope.ca - 2024-12-08 19:50 +0100
  Re: Shell function & variable usage. eben@gmx.us - 2024-12-07 00:50 +0100
    Re: Shell function & variable usage. eben@gmx.us - 2024-12-07 01:00 +0100
    Re: Shell function & variable usage. Greg Wooledge <greg@wooledge.org> - 2024-12-07 01:00 +0100
  Re: Shell function & variable usage. Karl Vogel <vogelke@pobox.com> - 2024-12-07 12:40 +0100
  Re: Shell function & variable usage. Anssi Saari <anssi.saari@debian-user.mail.kapsi.fi> - 2024-12-11 14:30 +0100

csiph-web