help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question that baffles AI (all of them)


From: alex xmb sw ratchev
Subject: Re: Question that baffles AI (all of them)
Date: Sun, 16 Jun 2024 04:56:56 +0200

On Sun, Jun 16, 2024, 3:52 AM Saint Michael <venefax@gmail.com> wrote:

>   np() {
> declare IFS=', '
> set -- $*
> IFS=$' \t\n'
>  if (( $# == 1 )) ; then
> printf %s\\n "$1"
>  else
> printf %s "$1"
> printf ', %s' "${@:2}"
> printf \\n
>  fi
>   }
>
>  for f ; do
> np "$f"
>  done
> -------
> dat.sh 1 2 "the is a really long text that has ! commas,, and #3 , a, b" 4
> 5
> 1
> 2
> the, is, a, really, long, text, that, has, !, commas, , and, #3, a, b
> 4
> 5
> So there does not seem an obvious way to do this.
> Any ideas about how to send an arbitrary string to a bash script and
> get into a variable, without alterations?
>

var=$1
var=$* / var=$@
var=${@:3} # third and more arg
var=( "${@:3}" ) # array
$# numbers of args

On Sat, Jun 15, 2024 at 8:12 PM alex xmb sw ratchev <fxmbsw7@gmail.com>
> wrote:
> >
> > bash dat.sh.2 1 2 "3 , a, b" 4 5
> > 1
> > 2
> > 3, a, b
> > 4
> > 5
> >
> >
> > maybe u actually ask to not printf but actually act on those values ..
> >
> >
> > On Sun, Jun 16, 2024, 1:44 AM Saint Michael <venefax@gmail.com> wrote:
> >>
> >> # numproc
> >>   np() {
> >> declare IFS=', '
> >> set -- $*
> >> IFS=$' \t\n'
> >>  while (( $# >1 )) ; do
> >> echo $1
> >> shift
> >>  done
> >>   }
> >>
> >> np "$*"
> >>
> >> if I call your example with: dat.sh 1 2 "3 , a, b" 4 5
> >> how do I get
> >> 1
> >> 2
> >> 3 , 1, b
> >> 4
> >> 5
> >>
> >>
> >> On Sat, Jun 15, 2024 at 5:48 PM alex xmb sw ratchev <fxmbsw7@gmail.com>
> wrote:
> >> >
> >> > bash dat.sh.1 1,2,3,4
> >> > a 1  ,  b 2
> >> > a 3  ,  b 4
> >> >
> >> >
> >> > or u meant to equally split the args ?
> >> >
> >> > On Sat, Jun 15, 2024, 11:30 PM Saint Michael <venefax@gmail.com>
> wrote:
> >> >>
> >> >> in this code:
> >> >> data="'1,2,3,4','5,6,7,8'"
> >> >>
> >> >> # Define the processing function
> >> >> process() {
> >> >> echo "There are $# arguments."
> >> >>     echo "They are: $@"
> >> >>     local job="$1"
> >> >>     shift
> >> >>     local a="$1"
> >> >>     shift
> >> >>     local b="$1"
> >> >>     shift
> >> >>     local remaining="$*"
> >> >>     echo "Arg1: '$a', Arg2: '$b'"
> >> >> }
> >> >> process "$data"
> >> >>
> >> >> how can I get my (a) and (b) arguments right?
> >> >> The length of both strings is unpredictable.
> >> >> a="1,2,3,4" and b="5,6,7,8""
> >> >>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]