Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

If you're not part of the solution, you're part of the precipitate.


devel / comp.unix.shell / exit in script

SubjectAuthor
* exit in scriptvjp2.at
`* Re: exit in scriptJanis Papanagnou
 +* Re: exit in scriptvjp2.at
 |`* Re: exit in scriptJanis Papanagnou
 | `* Re: exit in scriptvjp2.at
 |  `* Re: exit in scriptJanis Papanagnou
 |   +- Re: exit in scriptvjp2.at
 |   `* Re: exit in scriptGeoff Clare
 |    `* Re: exit in scriptJanis Papanagnou
 |     +- Re: exit in scriptHelmut Waitzmann
 |     `- Re: exit in scriptGeoff Clare
 `* Re: exit in scriptvjp2.at
  `* Re: exit in scriptJanis Papanagnou
   `* Re: exit in scriptvjp2.at
    +* Re: exit in scriptvjp2.at
    |`- Re: exit in scriptJanis Papanagnou
    `- Re: exit in scriptJanis Papanagnou

1
exit in script

<somusu$e16$1@reader1.panix.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4683&group=comp.unix.shell#4683

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix2.panix.com!not-for-mail
From: vjp2...@at.BioStrategist.dot.dot.com
Newsgroups: comp.unix.shell
Subject: exit in script
Date: Tue, 7 Dec 2021 06:27:42 -0000 (UTC)
Organization: Samani Marions Panyaught NYC-11357-3436-287-USA
Message-ID: <somusu$e16$1@reader1.panix.com>
Injection-Date: Tue, 7 Dec 2021 06:27:42 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix2.panix.com:166.84.1.2";
logging-data="14374"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: vjp2...@at.BioStrategist.dot.dot.com - Tue, 7 Dec 2021 06:27 UTC

I want to make a proc that does

run first
echo enough
read nuff
if nuff then exit
else second
exhout enough
read nuff
if nuff then exit
else third

I'm unclear about the if/exit syntax

--
Vasos Panagiotopoulos panix.com/~vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---

Re: exit in script

<son1pb$qe5$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4684&group=comp.unix.shell#4684

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Tue, 7 Dec 2021 08:16:59 +0100
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <son1pb$qe5$1@dont-email.me>
References: <somusu$e16$1@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 7 Dec 2021 07:16:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="dbf2d7ee74472c26bdfc0af2664574bf";
logging-data="27077"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eYKdBKRSmUP5Tf7m+nkb7"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:lxHlaQnSzZyOJiR8T/3UtAVaekQ=
In-Reply-To: <somusu$e16$1@reader1.panix.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Tue, 7 Dec 2021 07:16 UTC

On 07.12.2021 07:27, vjp2.at@at.BioStrategist.dot.dot.com wrote:
> I want to make a proc that does
>
> run first
> echo enough
> read nuff
> if nuff then exit
> else second
> exhout enough
> read nuff
> if nuff then exit
> else third
>
> I'm unclear about the if/exit syntax

Assuming you are using a modern shell (ksh, bash, zsh),
assuming 'first' and 'second' and 'third' are commands or programs,
assuming by "if nuff" you want to test against non-empty input,
and I left out (commented out) the exhout thing (no idea what you mean),
finally you may (or may not) want to provide an exit code to 'exit'
('exit 0' if successful, 'exit 1' to return an error indication.

first
echo enough
read nuff
if [[ -n "$nuff" ]]
then exit
else second
fi
# exhout enough
read nuff
if [[ -n "$nuff" ]]
then exit
else third
fi

Janis

Re: exit in script

<sopg4m$5bm$1@reader1.panix.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4687&group=comp.unix.shell#4687

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: vjp2...@at.BioStrategist.dot.dot.com
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Wed, 8 Dec 2021 05:34:14 -0000 (UTC)
Organization: Samani Marions Panyaught NYC-11357-3436-287-USA
Message-ID: <sopg4m$5bm$1@reader1.panix.com>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
Injection-Date: Wed, 8 Dec 2021 05:34:14 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="5494"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: vjp2...@at.BioStrategist.dot.dot.com - Wed, 8 Dec 2021 05:34 UTC

In <son1pb$qe5$1@dont-email.me> by Janis Papanagnou <janis_papanagnou@hotmail.com> on Tue, 07 Dec 2021 02:16:59 we perused:
*+-On 07.12.2021 07:27, vjp2.at@at.BioStrategist.dot.dot.com wrote:
*+-> I want to make a proc that does
*+->
*+-> run first
*+-> echo enough
*+-> read nuff
*+-> if nuff then exit
*+-> else second
*+-> exhout enough
*+-> read nuff
*+-> if nuff then exit
*+-> else third
*+->
*+-> I'm unclear about the if/exit syntax

*+-Assuming you are using a modern shell (ksh, bash, zsh),
*+-assuming 'first' and 'second' and 'third' are commands or programs,
*+-assuming by "if nuff" you want to test against non-empty input,
*+-and I left out (commented out) the exhout thing (no idea what you mean),
*+-finally you may (or may not) want to provide an exit code to 'exit'
*+-('exit 0' if successful, 'exit 1' to return an error indication.

*+- first
*+- echo enough
*+- read nuff
*+- if [[ -n "$nuff" ]]
*+- then exit
*+- else second
*+- fi
*+- # exhout enough
*+- read nuff
*+- if [[ -n "$nuff" ]]
*+- then exit
*+- else third
*+- fi

*+-Janis

Thanks much! The numbers after the exit confused me

--
Vasos Panagiotopoulos panix.com/~vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---

Re: exit in script

<sopg8q$5bm$2@reader1.panix.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4688&group=comp.unix.shell#4688

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: vjp2...@at.BioStrategist.dot.dot.com
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Wed, 8 Dec 2021 05:36:26 -0000 (UTC)
Organization: Samani Marions Panyaught NYC-11357-3436-287-USA
Message-ID: <sopg8q$5bm$2@reader1.panix.com>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
Injection-Date: Wed, 8 Dec 2021 05:36:26 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="5494"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: vjp2...@at.BioStrategist.dot.dot.com - Wed, 8 Dec 2021 05:36 UTC

Basically I want to run the same search through three search engines
(brave, qwant, dogpile) but if I'm happy witht he first round,
stop searching.

--
Vasos Panagiotopoulos panix.com/~vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---

Re: exit in script

<sophld$lk0$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4689&group=comp.unix.shell#4689

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Wed, 8 Dec 2021 07:00:12 +0100
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <sophld$lk0$1@dont-email.me>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
<sopg4m$5bm$1@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 8 Dec 2021 06:00:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="629f11d626b9f89f9f11ebb5dfe671c0";
logging-data="22144"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eUnCDN8beYL1CMpYRFz2E"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:lUNM7YcVLSQR2wKhPb653TgdwN4=
In-Reply-To: <sopg4m$5bm$1@reader1.panix.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Wed, 8 Dec 2021 06:00 UTC

On 08.12.2021 06:34, vjp2.at@at.BioStrategist.dot.dot.com wrote:
> In <son1pb$qe5$1@dont-email.me> by Janis Papanagnou <janis_papanagnou@hotmail.com> on Tue, 07 Dec 2021 02:16:59 we perused:
> *+-On 07.12.2021 07:27, vjp2.at@at.BioStrategist.dot.dot.com wrote:
> *+->
> *+-> I'm unclear about the if/exit syntax
>
> *+-finally you may (or may not) want to provide an exit code to 'exit'
> *+-('exit 0' if successful, 'exit 1' to return an error indication.
>
> Thanks much! The numbers after the exit confused me

'exit' is a command that exits the script and passes a return code
to the caller so that the caller can determine the processing state
(like success or various fail situations) of the called script.

A value of 0 indicates success, and values >0 indicate some sort of
error, or warning, or other state necessary/sensible in your context.

Say, you have a script "any_args" defined as

if [[ $# != 0 ]] ; then exit 0 ; else exit 1 ; fi

then you can call it like that

any_args
or
any_args A B C

and get a failure code in the first case and a success indication in
the second case. So you can embed that in code, e.g.

if any_args ${unknown_content}
then echo arguments provided
else echo no arguments
fi

Error and status handling is crucial in programming, also in shell.

Janis

Re: exit in script

<sophpf$k3r$1@reader1.panix.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4690&group=comp.unix.shell#4690

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: vjp2...@at.BioStrategist.dot.dot.com
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Wed, 8 Dec 2021 06:02:23 -0000 (UTC)
Organization: Samani Marions Panyaught NYC-11357-3436-287-USA
Message-ID: <sophpf$k3r$1@reader1.panix.com>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me> <sopg4m$5bm$1@reader1.panix.com> <sophld$lk0$1@dont-email.me>
Injection-Date: Wed, 8 Dec 2021 06:02:23 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="20603"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: vjp2...@at.BioStrategist.dot.dot.com - Wed, 8 Dec 2021 06:02 UTC

Thanks, I got it, worked on first try!! :

wearch () {
SRCH=`echo $* | sed -e 's/ /+/g'`;
lynx -accept_all_cookies -useragent 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0' 'https://search.brave.com/search?q='$SRCH ;
echo "return if enough else qwant";
read nuff;
if [[ -n "$nuff" ]]
then exit
else lynx -accept_all_cookies -useragent 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0' 'https://www.qwant.com/?q='$SRCH ;
fi;
echo "return if enough else dogpile";
read nuff;
if [[ -n "$nuff" ]]
then exit
else lynx -accept_all_cookies -useragent 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0' 'http://www.dogpile.com/search/web?q='$SRCH ;
fi;
}

--
Vasos Panagiotopoulos panix.com/~vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---

Re: exit in script

<sopi2t$n3j$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4691&group=comp.unix.shell#4691

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Wed, 8 Dec 2021 07:07:25 +0100
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <sopi2t$n3j$1@dont-email.me>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
<sopg8q$5bm$2@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 8 Dec 2021 06:07:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="629f11d626b9f89f9f11ebb5dfe671c0";
logging-data="23667"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gLl0e7bIgL75ssKPgO3Zs"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:hREoZtV5ZDG0KVsolzv5LKA+GsU=
In-Reply-To: <sopg8q$5bm$2@reader1.panix.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Wed, 8 Dec 2021 06:07 UTC

On 08.12.2021 06:36, vjp2.at@at.BioStrategist.dot.dot.com wrote:
> Basically I want to run the same search through three search engines
> (brave, qwant, dogpile) but if I'm happy witht he first round,
> stop searching.

Then another logic, a loop, might be preferable. Something like

for search_engine in brave qwant dogpile
do
"$search_engine" whatever arguments
echo "continue? (y/n)" ; read yn
[[ "$yn" != "y" ]] && exit 0
done
echo "nothing appropriate found"
exit 1

Janis

Re: exit in script

<sos57v$ja3$1@reader1.panix.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4693&group=comp.unix.shell#4693

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: vjp2...@at.BioStrategist.dot.dot.com
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Thu, 9 Dec 2021 05:46:39 -0000 (UTC)
Organization: Samani Marions Panyaught NYC-11357-3436-287-USA
Message-ID: <sos57v$ja3$1@reader1.panix.com>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me> <sopg8q$5bm$2@reader1.panix.com> <sopi2t$n3j$1@dont-email.me>
Injection-Date: Thu, 9 Dec 2021 05:46:39 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="19779"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: vjp2...@at.BioStrategist.dot.dot.com - Thu, 9 Dec 2021 05:46 UTC

Not really, but I think the second if should be an elif
and exit lands me back in my interrupted login script
which makes me wonder if it might not also log me off.
I changed the -n to -z because "no" exited

--
Vasos Panagiotopoulos panix.com/~vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---

Re: exit in script

<sos5io$cn1$1@reader1.panix.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4694&group=comp.unix.shell#4694

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: vjp2...@at.BioStrategist.dot.dot.com
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Thu, 9 Dec 2021 05:52:24 -0000 (UTC)
Organization: Samani Marions Panyaught NYC-11357-3436-287-USA
Message-ID: <sos5io$cn1$1@reader1.panix.com>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me> <sopg8q$5bm$2@reader1.panix.com> <sopi2t$n3j$1@dont-email.me> <sos57v$ja3$1@reader1.panix.com>
Injection-Date: Thu, 9 Dec 2021 05:52:24 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="13025"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: vjp2...@at.BioStrategist.dot.dot.com - Thu, 9 Dec 2021 05:52 UTC

exit does indeed log me out

yikes

foolish of me to think it would work on the first try

--
Vasos Panagiotopoulos panix.com/~vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---

Re: exit in script

<sos93b$8nd$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4695&group=comp.unix.shell#4695

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Thu, 9 Dec 2021 07:52:27 +0100
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <sos93b$8nd$1@dont-email.me>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
<sopg8q$5bm$2@reader1.panix.com> <sopi2t$n3j$1@dont-email.me>
<sos57v$ja3$1@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 9 Dec 2021 06:52:27 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f0e890787a90cb4a6a75557f6e9b48ea";
logging-data="8941"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19c9zmI6n0PPuNVkB65NmDc"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:0978+NSsL2BjHnShGfiRoUAUxp8=
In-Reply-To: <sos57v$ja3$1@reader1.panix.com>
 by: Janis Papanagnou - Thu, 9 Dec 2021 06:52 UTC

On 09.12.2021 06:46, vjp2.at@at.BioStrategist.dot.dot.com wrote:
> Not really, but I think the second if should be an elif
> and exit lands me back in my interrupted login script
> which makes me wonder if it might not also log me off.
> I changed the -n to -z because "no" exited
>

This is Usenet. Without posted context your post is usually
incomprehensible.

Janis

Re: exit in script

<sos96o$8nd$2@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4696&group=comp.unix.shell#4696

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Thu, 9 Dec 2021 07:54:16 +0100
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <sos96o$8nd$2@dont-email.me>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
<sopg8q$5bm$2@reader1.panix.com> <sopi2t$n3j$1@dont-email.me>
<sos57v$ja3$1@reader1.panix.com> <sos5io$cn1$1@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 9 Dec 2021 06:54:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f0e890787a90cb4a6a75557f6e9b48ea";
logging-data="8941"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Omk9w15/epNlAqG74D8wT"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:qYFygO8kfjfU5O34CEkAHNuVX8I=
In-Reply-To: <sos5io$cn1$1@reader1.panix.com>
 by: Janis Papanagnou - Thu, 9 Dec 2021 06:54 UTC

On 09.12.2021 06:52, vjp2.at@at.BioStrategist.dot.dot.com wrote:
> exit does indeed log me out

'exit' terminates the program that contains that command.
If used interactively from a shell session it will exit the shell.

If you want to return from a function use 'return'.

Janis

Re: exit in script

<sosafp$gbn$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4697&group=comp.unix.shell#4697

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Thu, 9 Dec 2021 08:16:09 +0100
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <sosafp$gbn$1@dont-email.me>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
<sopg4m$5bm$1@reader1.panix.com> <sophld$lk0$1@dont-email.me>
<sophpf$k3r$1@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 9 Dec 2021 07:16:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f0e890787a90cb4a6a75557f6e9b48ea";
logging-data="16759"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+DdbhGNX8sxIwNO4G73uIQ"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:NhNTQP75Uku/HejVf0oGaiw4Xqc=
In-Reply-To: <sophpf$k3r$1@reader1.panix.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Thu, 9 Dec 2021 07:16 UTC

On 08.12.2021 07:02, vjp2.at@at.BioStrategist.dot.dot.com wrote:
> Thanks, I got it, worked on first try!! :
>
> wearch () {
> SRCH=`echo $* | sed -e 's/ /+/g'`;
> lynx -accept_all_cookies -useragent 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0' 'https://search.brave.com/search?q='$SRCH ;
> echo "return if enough else qwant";
> read nuff;
> if [[ -n "$nuff" ]]
> then exit
> else lynx -accept_all_cookies -useragent 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0' 'https://www.qwant.com/?q='$SRCH ;
> fi;
> echo "return if enough else dogpile";
> read nuff;
> if [[ -n "$nuff" ]]
> then exit
> else lynx -accept_all_cookies -useragent 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0' 'http://www.dogpile.com/search/web?q='$SRCH ;
> fi;
> }

Based on the code above and some comments dispersed in the thread
you may want to have a look at the subsequent code with changes

* substitution is done by shell (without sed)
* browser ID is extracted in one place
* a loop is used (simply extensible for more search engines)
* exit is replaced by return
* search will only be continued with next engine if 'y' is typed
* if no search reult are not accepted by user then status 1 is returned
* otherwise status 0
* the # commented line needs to be uncommented to operate
* the code requires a modern shell to run like ksh, bash, zsh

Hope that helps.

Janis

wearch()
{
ARGS=$*
SRCH=${ARGS// /+}
id='Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0'
for search_engine in \
'https://search.brave.com/search' \
'https://www.qwant.com/' \
'http://www.dogpile.com/search/web'
do
echo "do search with $search_engine"
# lynx -accept_all_cookies -useragent "$id" "$search_engine?q=$SRCH"
echo "continue? (y/n)" ; read yn
[[ "$yn" != "y" ]] && return 0
done
echo "nothing appropriate found"
return 1
}

wearch Janis Joplin
echo search returned state $?

Re: exit in script

<soumo6$987$1@reader1.panix.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4698&group=comp.unix.shell#4698

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: vjp2...@at.BioStrategist.dot.dot.com
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Fri, 10 Dec 2021 04:57:42 -0000 (UTC)
Organization: Samani Marions Panyaught NYC-11357-3436-287-USA
Message-ID: <soumo6$987$1@reader1.panix.com>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me> <sopg4m$5bm$1@reader1.panix.com> <sophld$lk0$1@dont-email.me> <sophpf$k3r$1@reader1.panix.com> <sosafp$gbn$1@dont-email.me>
Injection-Date: Fri, 10 Dec 2021 04:57:42 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="9479"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: vjp2...@at.BioStrategist.dot.dot.com - Fri, 10 Dec 2021 04:57 UTC

Thanks

--
Vasos Panagiotopoulos panix.com/~vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---

Re: exit in script

<h02c8i-upd.ln1@ID-313840.user.individual.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4699&group=comp.unix.shell#4699

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: geo...@clare.See-My-Signature.invalid (Geoff Clare)
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Fri, 10 Dec 2021 13:41:05 +0000
Lines: 35
Message-ID: <h02c8i-upd.ln1@ID-313840.user.individual.net>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
<sopg4m$5bm$1@reader1.panix.com> <sophld$lk0$1@dont-email.me>
<sophpf$k3r$1@reader1.panix.com> <sosafp$gbn$1@dont-email.me>
Reply-To: netnews@gclare.org.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net vE2eF/t618Mw9IqMzPQWuwGhgmvSOWpHE8H6kjXyOdNsrYvMjR
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:C2LMDvBDUDGjfPX5yeQOdoCYF9I=
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
 by: Geoff Clare - Fri, 10 Dec 2021 13:41 UTC

Janis Papanagnou wrote:

> On 08.12.2021 07:02, vjp2.at@at.BioStrategist.dot.dot.com wrote:
>>
>> wearch () {
>> SRCH=`echo $* | sed -e 's/ /+/g'`;

> Based on the code above and some comments dispersed in the thread
> you may want to have a look at the subsequent code with changes
>
> * substitution is done by shell (without sed)

> wearch()
> {
> ARGS=$*
> SRCH=${ARGS// /+}

This change introduces a dependency on the value of IFS. It will
only work correctly if IFS is not empty and the first character is a
space (which it is by default, but IFS could be changed by code that
calls the wearch function).

My inclination would be to use a loop to build the SRCH value:

SRCH=""
for ARG
do
SRCH="$SRCH${SRCH:++}$ARG"
done

This, together with changing [[ "$yn" != "y" ]] to [ "$yn" != "y" ],
would make the function work with any POSIX shell.

--
Geoff Clare <netnews@gclare.org.uk>

Re: exit in script

<sovrne$61e$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4703&group=comp.unix.shell#4703

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Fri, 10 Dec 2021 16:28:46 +0100
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <sovrne$61e$1@dont-email.me>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
<sopg4m$5bm$1@reader1.panix.com> <sophld$lk0$1@dont-email.me>
<sophpf$k3r$1@reader1.panix.com> <sosafp$gbn$1@dont-email.me>
<h02c8i-upd.ln1@ID-313840.user.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 10 Dec 2021 15:28:46 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="668dce94f36490f5df68426bd50ef521";
logging-data="6190"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ZdL1QmB8lSUzm+jkMrdkU"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:GFyGD4NKQ0SB9wWQk5xw18AYLDU=
In-Reply-To: <h02c8i-upd.ln1@ID-313840.user.individual.net>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Fri, 10 Dec 2021 15:28 UTC

On 10.12.2021 14:41, Geoff Clare wrote:
> Janis Papanagnou wrote:
>
>> On 08.12.2021 07:02, vjp2.at@at.BioStrategist.dot.dot.com wrote:
>>>
>>> wearch () {
>>> SRCH=`echo $* | sed -e 's/ /+/g'`;
>
>> Based on the code above and some comments dispersed in the thread
>> you may want to have a look at the subsequent code with changes
>>
>> * substitution is done by shell (without sed)
>
>> wearch()
>> {
>> ARGS=$*
>> SRCH=${ARGS// /+}
>
> This change introduces a dependency on the value of IFS. It will
> only work correctly if IFS is not empty and the first character is a
> space (which it is by default, but IFS could be changed by code that
> calls the wearch function).

Interesting.

This simple change seems to work, though, with IFS=''

ARGS=$@
SRCH=${ARGS// /+}

(or please correct me if I am wrong).

(But I am puzzled at the moment why

ARGS=$@
SRCH=${ARGS// */+}

doesn't work. Guess I need some coffee.)

>
> My inclination would be to use a loop to build the SRCH value:
>
> SRCH=""
> for ARG
> do
> SRCH="$SRCH${SRCH:++}$ARG"
> done
>
> This, together with changing [[ "$yn" != "y" ]] to [ "$yn" != "y" ],
> would make the function work with any POSIX shell.

Or even make the y/n decision complete

case $yn in
(y|Y) ... ;;
(n|N) ... ;;
(*) ... ;;
esac

(also POSIX conforming).

Janis

Re: exit in script

<83czm48gve.fsf@helmutwaitzmann.news.arcor.de>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4706&group=comp.unix.shell#4706

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!l1FBIGUABvno2dleZxggkA.user.46.165.242.75.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Fri, 10 Dec 2021 19:16:53 +0100
Organization: Aioe.org NNTP Server
Message-ID: <83czm48gve.fsf@helmutwaitzmann.news.arcor.de>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
<sopg4m$5bm$1@reader1.panix.com> <sophld$lk0$1@dont-email.me>
<sophpf$k3r$1@reader1.panix.com> <sosafp$gbn$1@dont-email.me>
<h02c8i-upd.ln1@ID-313840.user.individual.net>
<sovrne$61e$1@dont-email.me>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mime-Version: 1.0
Content-Type: text/plain; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="33362"; posting-host="l1FBIGUABvno2dleZxggkA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Mail-Copies-To: nobody
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Cancel-Lock: sha1:HtPBKY7GXEJbOBvA1XV91U7ZPPI=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Helmut Waitzmann - Fri, 10 Dec 2021 18:16 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com>:

>(But I am puzzled at the moment why
>
> ARGS=$@
> SRCH=${ARGS// */+}
>
>doesn't work. Guess I need some coffee.)

Perhaps because the pattern is a shell pattern rather than a regular
expression?

Re: exit in script

<cutj8i-fcg.ln1@ID-313840.user.individual.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=4737&group=comp.unix.shell#4737

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: geo...@clare.See-My-Signature.invalid (Geoff Clare)
Newsgroups: comp.unix.shell
Subject: Re: exit in script
Date: Mon, 13 Dec 2021 13:20:44 +0000
Lines: 48
Message-ID: <cutj8i-fcg.ln1@ID-313840.user.individual.net>
References: <somusu$e16$1@reader1.panix.com> <son1pb$qe5$1@dont-email.me>
<sopg4m$5bm$1@reader1.panix.com> <sophld$lk0$1@dont-email.me>
<sophpf$k3r$1@reader1.panix.com> <sosafp$gbn$1@dont-email.me>
<h02c8i-upd.ln1@ID-313840.user.individual.net> <sovrne$61e$1@dont-email.me>
Reply-To: netnews@gclare.org.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net u/OZIicYo6G12jiD3FhkGgO+cb6EyeCE11ADEJ4+HUhnnE2eVx
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:sG90pwsFRppDllTw2LVa8335RCI=
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
 by: Geoff Clare - Mon, 13 Dec 2021 13:20 UTC

Janis Papanagnou wrote:

> On 10.12.2021 14:41, Geoff Clare wrote:
>> Janis Papanagnou wrote:
>>
>>> On 08.12.2021 07:02, vjp2.at@at.BioStrategist.dot.dot.com wrote:
>>>>
>>>> wearch () {
>>>> SRCH=`echo $* | sed -e 's/ /+/g'`;
>>
>>> Based on the code above and some comments dispersed in the thread
>>> you may want to have a look at the subsequent code with changes
>>>
>>> * substitution is done by shell (without sed)
>>
>>> wearch()
>>> {
>>> ARGS=$*
>>> SRCH=${ARGS// /+}
>>
>> This change introduces a dependency on the value of IFS. It will
>> only work correctly if IFS is not empty and the first character is a
>> space (which it is by default, but IFS could be changed by code that
>> calls the wearch function).
>
> Interesting.
>
> This simple change seems to work, though, with IFS=''
>
> ARGS=$@
> SRCH=${ARGS// /+}
>
> (or please correct me if I am wrong).

It only works with some shells. They differ in how they expand $@ in
an assignment. (POSIX says the behaviour is unspecified.)

$ bash -c 'set one two three; IFS=""; x=$@; echo "$x"'
one two three
$ ksh -c 'set one two three; IFS=""; x=$@; echo "$x"'
one two three
$ dash -c 'set one two three; IFS=""; x=$@; echo "$x"'
onetwothree
$ busybox sh -c 'set one two three; IFS=""; x=$@; echo "$x"'
onetwothree

--
Geoff Clare <netnews@gclare.org.uk>

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor