Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

The disks are getting full; purge a file today.


devel / comp.unix.shell / Re: compound command

SubjectAuthor
* compound commandBit Twister
+* compound commandKeith Thompson
|+- [SOLUTION] compound commandBit Twister
|`- compound commandEd Morton
+* compound commandJanis Papanagnou
|`* compound commandBit Twister
| +- compound commandJanis Papanagnou
| `- compound commandJanis Papanagnou
`* compound commandlxvs
 `* compound commandKeith Thompson
  `* compound commandZhao-hui Liu
   `* compound commandKeith Thompson
    `* compound commandJanis Papanagnou
     `- compound commandKeith Thompson

1
compound command

<slrntth8pi.1903k.BitTwister@wb.home.arpa>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7219&group=comp.unix.shell#7219

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: BitTwister@mouse-potato.com (Bit Twister)
Newsgroups: comp.unix.shell
Subject: compound command
Date: Mon, 30 Jan 2023 23:12:16 -0600
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
Injection-Info: reader01.eternal-september.org; posting-host="e071474ba7bfb3ec56cc36407f7a89f7";
logging-data="3865154"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yMVTsjAEY8bK8Xd11bpoKriukjvPG1gA="
User-Agent: slrn/pre1.0.4-6 (Linux)
Cancel-Lock: sha1:GxWHNyqwF+TU96OjBZcFvSW+Ygc=
 by: Bit Twister - Tue, 31 Jan 2023 05:12 UTC

Downloaded ShellCheck-0.9.0-1.2.x86_64.rpm
ran

# shellcheck -x 00_common_changes

In 00_common_changes line 29:
cd /etc/rsyslog.d
^---------------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Did you mean:
cd /etc/rsyslog.d || exit

What came to mind that the script would exit without telling me why.

So I changed it to
cd /etc/rsyslog.d || echo "cd /etc/rsyslog.d failed" ; exit
script exits, guess because of ; exit

So I thought braces would solve my problem but I get
cd /etc/rsyslog.d || { echo "cd /etc/rsyslog.d failed" ; exit}
>
which indicates it is waiting for more input and I can not see why.

Any suggestions for cleaning up the problem.

Other option is do a
if [ $? -ne 0 ] ; then
echo "cd /etc/rsyslog.d failed"
exit
fi.

$ bash --version
bash --version
GNU bash, version 5.2.15(1)-release (x86_64-mageia-linux-gnu)

Re: compound command

<87ilgngtyo.fsf@nosuchdomain.example.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7220&group=comp.unix.shell#7220

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: compound command
Date: Mon, 30 Jan 2023 21:21:19 -0800
Organization: None to speak of
Lines: 16
Message-ID: <87ilgngtyo.fsf@nosuchdomain.example.com>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="3db9a2b1e0883f84b12ed711371ed774";
logging-data="3871552"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+hC0PpWQY5qpuUtuGecpBU"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:e9Y4LScMmcDfYyc3DheX/vvhbUY=
sha1:dTYVpYXR7MrNfrbnkLvqG8QL0MY=
 by: Keith Thompson - Tue, 31 Jan 2023 05:21 UTC

Bit Twister <BitTwister@mouse-potato.com> writes:
[...]
> So I thought braces would solve my problem but I get
> cd /etc/rsyslog.d || { echo "cd /etc/rsyslog.d failed" ; exit}
[...]

It's parsing `exit}` as a single command name (and if you added a space
it would treat `}` as an argument to `exit`). Add a semicolon after
"exit".

cd /etc/rsyslog.d || { echo "cd /etc/rsyslog.d failed"; exit; }

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Re: compound command

<tra8o0$3m77n$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7221&group=comp.unix.shell#7221

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: compound command
Date: Tue, 31 Jan 2023 06:25:20 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <tra8o0$3m77n$1@dont-email.me>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 31 Jan 2023 05:25:20 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="ba8834bbc242f5add509d9fbc62a8059";
logging-data="3874039"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192OASg8P3kP1Ql1dts8Qp0"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:K1+u7CwfY7TbcjU0KI/U90Rmzbc=
In-Reply-To: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Tue, 31 Jan 2023 05:25 UTC

On 31.01.2023 06:12, Bit Twister wrote:
> Downloaded ShellCheck-0.9.0-1.2.x86_64.rpm
> ran
>
> # shellcheck -x 00_common_changes
>
> In 00_common_changes line 29:
> cd /etc/rsyslog.d
> ^---------------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
>
> Did you mean:
> cd /etc/rsyslog.d || exit
>
>
> What came to mind that the script would exit without telling me why.
>
> So I changed it to
> cd /etc/rsyslog.d || echo "cd /etc/rsyslog.d failed" ; exit
> script exits, guess because of ; exit
>
> So I thought braces would solve my problem but I get
> cd /etc/rsyslog.d || { echo "cd /etc/rsyslog.d failed" ; exit}

Does this work without error? - I'd have expected { ... ; exit ;}

>>
> which indicates it is waiting for more input and I can not see why.

exit}

is a non-existing command, and the opening { is thus not closed.

>
> Any suggestions for cleaning up the problem.

Besides above fix I usually provide a function to simplify the code
with an optional error code

cd some_dir || err_exit "some msg" 42

For warnings a '0' (or no) value may just print the message without
exiting.

Janis

>
> Other option is do a
> if [ $? -ne 0 ] ; then
> echo "cd /etc/rsyslog.d failed"
> exit
> fi.
>
> $ bash --version
> bash --version
> GNU bash, version 5.2.15(1)-release (x86_64-mageia-linux-gnu)
>
>

Re: [SOLUTION] compound command

<slrnttheu5.19d9u.BitTwister@wb.home.arpa>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7222&group=comp.unix.shell#7222

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: BitTwister@mouse-potato.com (Bit Twister)
Newsgroups: comp.unix.shell
Subject: Re: [SOLUTION] compound command
Date: Tue, 31 Jan 2023 00:57:09 -0600
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <slrnttheu5.19d9u.BitTwister@wb.home.arpa>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
<87ilgngtyo.fsf@nosuchdomain.example.com>
Injection-Info: reader01.eternal-september.org; posting-host="e071474ba7bfb3ec56cc36407f7a89f7";
logging-data="3898626"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eeBkcJTeeapcPesF7x76bHt7qV+wbDko="
User-Agent: slrn/pre1.0.4-6 (Linux)
Cancel-Lock: sha1:WowcD5slJmdGgNbF3ZwzXbVyZ2E=
 by: Bit Twister - Tue, 31 Jan 2023 06:57 UTC

On Mon, 30 Jan 2023 21:21:19 -0800, Keith Thompson wrote:
> Bit Twister <BitTwister@mouse-potato.com> writes:
> [...]
>> So I thought braces would solve my problem but I get
>> cd /etc/rsyslog.d || { echo "cd /etc/rsyslog.d failed" ; exit}
> [...]
>
> It's parsing `exit}` as a single command name (and if you added a space
> it would treat `}` as an argument to `exit`). Add a semicolon after
> "exit".
>
> cd /etc/rsyslog.d || { echo "cd /etc/rsyslog.d failed"; exit; }

that is the solution.

Re: compound command

<slrntthf72.19d9u.BitTwister@wb.home.arpa>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7223&group=comp.unix.shell#7223

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: BitTwister@mouse-potato.com (Bit Twister)
Newsgroups: comp.unix.shell
Subject: Re: compound command
Date: Tue, 31 Jan 2023 01:01:51 -0600
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <slrntthf72.19d9u.BitTwister@wb.home.arpa>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
<tra8o0$3m77n$1@dont-email.me>
Injection-Info: reader01.eternal-september.org; posting-host="e071474ba7bfb3ec56cc36407f7a89f7";
logging-data="3898626"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/CNFLz1FICqu+WM6gboDwMnJRWHUm2d0U="
User-Agent: slrn/pre1.0.4-6 (Linux)
Cancel-Lock: sha1:MDUXDM+YQLHSIy0FBaSfI/IiU1U=
 by: Bit Twister - Tue, 31 Jan 2023 07:01 UTC

On Tue, 31 Jan 2023 06:25:20 +0100, Janis Papanagnou wrote:
> On 31.01.2023 06:12, Bit Twister wrote:
>> Downloaded ShellCheck-0.9.0-1.2.x86_64.rpm
>> ran
>>
>> # shellcheck -x 00_common_changes
>>
>> In 00_common_changes line 29:
>> cd /etc/rsyslog.d
>> ^---------------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
>>
>> Did you mean:
>> cd /etc/rsyslog.d || exit
>>
>>
>> What came to mind that the script would exit without telling me why.
>>
>> So I changed it to
>> cd /etc/rsyslog.d || echo "cd /etc/rsyslog.d failed" ; exit
>> script exits, guess because of ; exit
>>
>> So I thought braces would solve my problem but I get
>> cd /etc/rsyslog.d || { echo "cd /etc/rsyslog.d failed" ; exit}
>
> Does this work without error? - I'd have expected { ... ; exit ;}
>
>>>
>> which indicates it is waiting for more input and I can not see why.
>
> exit}
>
> is a non-existing command, and the opening { is thus not closed.
>
>>
>> Any suggestions for cleaning up the problem.
>
> Besides above fix I usually provide a function to simplify the code
> with an optional error code
>
> cd some_dir || err_exit "some msg" 42
>
> For warnings a '0' (or no) value may just print the message without
> exiting.

Yeah I had thought of the function. I am trying to get rid of the message
so I tried this, but not getting a line of code in the message.
$ t
/home/bittwister/local/work/t: line 12: cd: /aa/: No such file or directory
rtn code is 1
FAILED with 1

was trying the get the line of code before FAILED with 1

#!/bin/bash

function ucd ()
{ _rtn=$?
echo "rtn code is $_rtn "
_msg="${BASH_SOURCE[${BASH_LINENO[0]}]} "
echo "$_msg FAILED with $_rtn"
exit $_rtn
} # function ucd

cd /aa/ || ucd

exit

Re: compound command

<traftc$3ndfu$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7224&group=comp.unix.shell#7224

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: compound command
Date: Tue, 31 Jan 2023 08:27:40 +0100
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <traftc$3ndfu$1@dont-email.me>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
<tra8o0$3m77n$1@dont-email.me> <slrntthf72.19d9u.BitTwister@wb.home.arpa>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 31 Jan 2023 07:27:40 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="ba8834bbc242f5add509d9fbc62a8059";
logging-data="3913214"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/HsLpoKSzUSR9hAzjpB7l"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:RUs2L9SQhDxOot8u1At+IbSFpbU=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <slrntthf72.19d9u.BitTwister@wb.home.arpa>
 by: Janis Papanagnou - Tue, 31 Jan 2023 07:27 UTC

On 31.01.2023 08:01, Bit Twister wrote:
> On Tue, 31 Jan 2023 06:25:20 +0100, Janis Papanagnou wrote:
>> On 31.01.2023 06:12, Bit Twister wrote:
>>> [...]
>>>
>>> So I thought braces would solve my problem but I get
>>> cd /etc/rsyslog.d || { echo "cd /etc/rsyslog.d failed" ; exit}
>>
>> Does this work without error? - I'd have expected { ... ; exit ;}
>>
>>>>
>>> which indicates it is waiting for more input and I can not see why.
>>
>> exit}
>>
>> is a non-existing command, and the opening { is thus not closed.
>>
>>>
>>> Any suggestions for cleaning up the problem.
>>
>> Besides above fix I usually provide a function to simplify the code
>> with an optional error code
>>
>> cd some_dir || err_exit "some msg" 42
>>
>> For warnings a '0' (or no) value may just print the message without
>> exiting.
>
> Yeah I had thought of the function. I am trying to get rid of the message
> so I tried this, but not getting a line of code in the message.

Well, my suggestion to use a function was meant to avoid more complex
braced expressions like the one I depicted as { echo "..." ; exit ;}
if you have error checks in many places.

Deviating from you original post you now want the source code line
number in the message as I understand...

> $ t
> /home/bittwister/local/work/t: line 12: cd: /aa/: No such file or directory
> rtn code is 1
> FAILED with 1
>
> was trying the get the line of code before FAILED with 1
>
> #!/bin/bash
>
> function ucd ()
> { _rtn=$?
> echo "rtn code is $_rtn "
> _msg="${BASH_SOURCE[${BASH_LINENO[0]}]} "

....but I cannot tell for bash; you'd have to inspect the man page for
these variables.

(In ksh I'd use _msg="${.sh.lineno} " here, but that doesn't help
you with bash. Sorry.)

Janis

> echo "$_msg FAILED with $_rtn"
> exit $_rtn
> } # function ucd
>
>
> cd /aa/ || ucd
>
> exit
>

Re: compound command

<trah68$3nkch$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7225&group=comp.unix.shell#7225

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: compound command
Date: Tue, 31 Jan 2023 08:49:28 +0100
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <trah68$3nkch$1@dont-email.me>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
<tra8o0$3m77n$1@dont-email.me> <slrntthf72.19d9u.BitTwister@wb.home.arpa>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 31 Jan 2023 07:49:28 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="ba8834bbc242f5add509d9fbc62a8059";
logging-data="3920273"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189AGkICaeSkjY94aC8n1o2"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:PFeimarbNnMwIxKLaLIm2HaHgxs=
In-Reply-To: <slrntthf72.19d9u.BitTwister@wb.home.arpa>
 by: Janis Papanagnou - Tue, 31 Jan 2023 07:49 UTC

On 31.01.2023 08:01, Bit Twister wrote:
>> [...]
>
> Yeah I had thought of the function. I am trying to get rid of the message
> so I tried this, but not getting a line of code in the message.
> $ t
> /home/bittwister/local/work/t: line 12: cd: /aa/: No such file or directory
> rtn code is 1
> FAILED with 1
>
> was trying the get the line of code before FAILED with 1
>
> #!/bin/bash
>
> function ucd ()
> { _rtn=$?
> echo "rtn code is $_rtn "
> _msg="${BASH_SOURCE[${BASH_LINENO[0]}]} "

Did you want to print the source and the line number here, two
individual variables? - This would be

_msg="${BASH_SOURCE}[${BASH_LINENO[0]}] "

(In your code you used the line number as index to the source name.)

Janis

> echo "$_msg FAILED with $_rtn"
> exit $_rtn
> } # function ucd
>
>
> cd /aa/ || ucd
>
> exit
>

Re: compound command

<trjev3$1h5v3$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7227&group=comp.unix.shell#7227

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: compound command
Date: Fri, 3 Feb 2023 11:06:43 -0600
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <trjev3$1h5v3$1@dont-email.me>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
<87ilgngtyo.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Feb 2023 17:06:43 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="c5c7516b65dd36c048e6c9f1a68b8932";
logging-data="1611747"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/u1dlQ+r0rjeX77AOVe8W2"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:ha2w5eEZPtL8rALJIUccQHqpsj8=
X-Antivirus-Status: Clean
X-Antivirus: Avast (VPS 230203-1, 2/2/2023), Outbound message
Content-Language: en-US
In-Reply-To: <87ilgngtyo.fsf@nosuchdomain.example.com>
 by: Ed Morton - Fri, 3 Feb 2023 17:06 UTC

On 1/30/2023 11:21 PM, Keith Thompson wrote:
> Bit Twister <BitTwister@mouse-potato.com> writes:
> [...]
>> So I thought braces would solve my problem but I get
>> cd /etc/rsyslog.d || { echo "cd /etc/rsyslog.d failed" ; exit}
> [...]
>
> It's parsing `exit}` as a single command name (and if you added a space
> it would treat `}` as an argument to `exit`). Add a semicolon after
> "exit".
>
> cd /etc/rsyslog.d || { echo "cd /etc/rsyslog.d failed"; exit; }
>

I'd make it

cd /etc/rsyslog.d || { rc="$?"; echo "cd /etc/rsyslog.d failed with
result $rc" >&2; exit "$rc"; }

or similar so you have the exit status in the error message, the error
message goes to stderr instead of stdout, and you exit the script with a
failure rather than success exit status.

Ed.

Re: compound command

<a1f13161-18eb-4ada-a9b2-1ddf3c3aecf5n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7229&group=comp.unix.shell#7229

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:1496:b0:3b9:bfdf:cc6 with SMTP id t22-20020a05622a149600b003b9bfdf0cc6mr2090937qtx.337.1675646372794;
Sun, 05 Feb 2023 17:19:32 -0800 (PST)
X-Received: by 2002:a81:91c4:0:b0:527:814c:fe35 with SMTP id
i187-20020a8191c4000000b00527814cfe35mr721181ywg.422.1675646372579; Sun, 05
Feb 2023 17:19:32 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 5 Feb 2023 17:19:32 -0800 (PST)
In-Reply-To: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
Injection-Info: google-groups.googlegroups.com; posting-host=61.220.117.110; posting-account=ulmABwoAAAAWeusX6KELoUwjBaBUAm0u
NNTP-Posting-Host: 61.220.117.110
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a1f13161-18eb-4ada-a9b2-1ddf3c3aecf5n@googlegroups.com>
Subject: Re: compound command
From: lllxvs@gmail.com (lxvs)
Injection-Date: Mon, 06 Feb 2023 01:19:32 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1417
 by: lxvs - Mon, 6 Feb 2023 01:19 UTC

On Tuesday, January 31, 2023 at 1:12:24 PM UTC+8, Bit Twister wrote:
> What came to mind that the script would exit without telling me why.
>
> So I changed it to
> cd /etc/rsyslog.d || echo "cd /etc/rsyslog.d failed" ; exit
> script exits, guess because of ; exit

cd will tell you why exited if failed, so `cd || exit' is fine.

Re: compound command

<87pmanvauc.fsf@nosuchdomain.example.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7230&group=comp.unix.shell#7230

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: compound command
Date: Sun, 05 Feb 2023 17:31:07 -0800
Organization: None to speak of
Lines: 28
Message-ID: <87pmanvauc.fsf@nosuchdomain.example.com>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
<a1f13161-18eb-4ada-a9b2-1ddf3c3aecf5n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="181ea74528ed435ea473c00f282e1c24";
logging-data="2934600"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JJPjUP5GoKjDt8jD3B1MU"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:YgImEaAXd6lQIavFoLrCSkFEUVc=
sha1:MDcIGrjqDCv1w+EOJJ2ESJrlKwE=
 by: Keith Thompson - Mon, 6 Feb 2023 01:31 UTC

lxvs <lllxvs@gmail.com> writes:
> On Tuesday, January 31, 2023 at 1:12:24 PM UTC+8, Bit Twister wrote:
>> What came to mind that the script would exit without telling me why.
>>
>> So I changed it to
>> cd /etc/rsyslog.d || echo "cd /etc/rsyslog.d failed" ; exit
>> script exits, guess because of ; exit
>
> cd will tell you why exited if failed, so `cd || exit' is fine.

I'd suggest `cd /etc/rsyslog.d || exit 1`, so the script indicates that
it failed.

$ cat tmp.sh
#!/bin/sh

cd /no/such/directory || exit 1
$ ./tmp.sh
../tmp.sh: 3: cd: can't cd to /no/such/directory
$ ./tmp.sh && echo OK || echo FAILED
../tmp.sh: 3: cd: can't cd to /no/such/directory
FAILED
$

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Re: compound command

<4984a1e2-8fad-4aad-a4d5-a6a79a1809ben@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7231&group=comp.unix.shell#7231

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:c6:b0:3b9:bbba:f444 with SMTP id p6-20020a05622a00c600b003b9bbbaf444mr1640694qtw.164.1675647644274;
Sun, 05 Feb 2023 17:40:44 -0800 (PST)
X-Received: by 2002:a81:ee0a:0:b0:510:475f:6529 with SMTP id
l10-20020a81ee0a000000b00510475f6529mr1986854ywm.272.1675647644077; Sun, 05
Feb 2023 17:40:44 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 5 Feb 2023 17:40:43 -0800 (PST)
In-Reply-To: <87pmanvauc.fsf@nosuchdomain.example.com>
Injection-Info: google-groups.googlegroups.com; posting-host=61.220.117.110; posting-account=ulmABwoAAAAWeusX6KELoUwjBaBUAm0u
NNTP-Posting-Host: 61.220.117.110
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa> <a1f13161-18eb-4ada-a9b2-1ddf3c3aecf5n@googlegroups.com>
<87pmanvauc.fsf@nosuchdomain.example.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4984a1e2-8fad-4aad-a4d5-a6a79a1809ben@googlegroups.com>
Subject: Re: compound command
From: lllxvs@gmail.com (Zhao-hui Liu)
Injection-Date: Mon, 06 Feb 2023 01:40:44 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1541
 by: Zhao-hui Liu - Mon, 6 Feb 2023 01:40 UTC

On Monday, February 6, 2023 at 9:31:14 AM UTC+8, Keith Thompson wrote:
> I'd suggest `cd /etc/rsyslog.d || exit 1`, so the script indicates that
> it failed.

`command || exit' is sufficient to indicate script failure, and better than `command || exit 1', because the latter always returns 1 if fails, while the former reflects the exit code of command.

Re: compound command

<87lelbv219.fsf@nosuchdomain.example.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7232&group=comp.unix.shell#7232

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: compound command
Date: Sun, 05 Feb 2023 20:41:22 -0800
Organization: None to speak of
Lines: 26
Message-ID: <87lelbv219.fsf@nosuchdomain.example.com>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
<a1f13161-18eb-4ada-a9b2-1ddf3c3aecf5n@googlegroups.com>
<87pmanvauc.fsf@nosuchdomain.example.com>
<4984a1e2-8fad-4aad-a4d5-a6a79a1809ben@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="181ea74528ed435ea473c00f282e1c24";
logging-data="3082237"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX181pgeBMZM26VEYYw139pm5"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:WIrqQVOgF0H5EV5WAauWM3cCqOI=
sha1:3/u8WEGYslIsxMdsw48zVKmb7/8=
 by: Keith Thompson - Mon, 6 Feb 2023 04:41 UTC

Zhao-hui Liu <lllxvs@gmail.com> writes:
> On Monday, February 6, 2023 at 9:31:14 AM UTC+8, Keith Thompson wrote:
>> I'd suggest `cd /etc/rsyslog.d || exit 1`, so the script indicates that
>> it failed.
>
> `command || exit' is sufficient to indicate script failure, and better
> than `command || exit 1', because the latter always returns 1 if
> fails, while the former reflects the exit code of command.

Good point.

I had forgotten that the built-in `exit` command with no arguments uses
the exit status of the last command executed. (POSIX specifies this.)

If you prefer to be more explicit (as I do), you can use `command || exit $?`.

(Anyone writing scripts in csh or tcsh for some reason should be aware
that, according to the respective man pages, csh's builtin `exit` with
no arguments exits with value of `$status`, but tcsh's `exit` exits with
a status of 0 -- and my quick experiment is not consistent with the man
pages.)

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Re: compound command

<trq71f$2vblr$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7233&group=comp.unix.shell#7233

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: compound command
Date: Mon, 6 Feb 2023 07:34:22 +0100
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <trq71f$2vblr$1@dont-email.me>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
<a1f13161-18eb-4ada-a9b2-1ddf3c3aecf5n@googlegroups.com>
<87pmanvauc.fsf@nosuchdomain.example.com>
<4984a1e2-8fad-4aad-a4d5-a6a79a1809ben@googlegroups.com>
<87lelbv219.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 6 Feb 2023 06:34:23 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="9af5646980c15361bbcb9bd99aaea7f0";
logging-data="3124923"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fBZqwhqDZ35KHR/JmAW9O"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:hX7xAeGViOvg55QLmmdasxCmkpU=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <87lelbv219.fsf@nosuchdomain.example.com>
 by: Janis Papanagnou - Mon, 6 Feb 2023 06:34 UTC

On 06.02.2023 05:41, Keith Thompson wrote:
> Zhao-hui Liu <lllxvs@gmail.com> writes:
>> On Monday, February 6, 2023 at 9:31:14 AM UTC+8, Keith Thompson wrote:
>>> I'd suggest `cd /etc/rsyslog.d || exit 1`, so the script indicates that
>>> it failed.
>>
>> `command || exit' is sufficient to indicate script failure, and better
>> than `command || exit 1', because the latter always returns 1 if
>> fails, while the former reflects the exit code of command.
>
> Good point.
>
> I had forgotten that the built-in `exit` command with no arguments uses
> the exit status of the last command executed. (POSIX specifies this.)
>
> If you prefer to be more explicit (as I do), you can use `command || exit $?`.

Notwithstanding there's a point in explicitly specifying an exit code
(i.e. different from $?), depending on where you come from.

If you think your scripts from a systems perspective you may not be
interested in the technical reason that $? (or a plain exit) provides;
you may want to get information from the software process as a whole,
effectively a process oriented abstraction layer. And the concrete
command's $? would go into a log file for technical debugging where
it matters.

BTW; what error codes does 'cd' return besides "1"? - The most common
cases [for me] are non-existing directories, access permissions, and
file type mismatch, all of them indicated with exit code "1" [in my
environment] (and differentiated only by the textual output on stderr).

Janis

Re: compound command

<87a61rupcl.fsf@nosuchdomain.example.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7234&group=comp.unix.shell#7234

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: compound command
Date: Mon, 06 Feb 2023 01:15:22 -0800
Organization: None to speak of
Lines: 49
Message-ID: <87a61rupcl.fsf@nosuchdomain.example.com>
References: <slrntth8pi.1903k.BitTwister@wb.home.arpa>
<a1f13161-18eb-4ada-a9b2-1ddf3c3aecf5n@googlegroups.com>
<87pmanvauc.fsf@nosuchdomain.example.com>
<4984a1e2-8fad-4aad-a4d5-a6a79a1809ben@googlegroups.com>
<87lelbv219.fsf@nosuchdomain.example.com>
<trq71f$2vblr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="181ea74528ed435ea473c00f282e1c24";
logging-data="3173026"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Q8qsEh1IJ3icTPAVA7USO"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:TwRxLJt90U19ovkuhR4rnsKBHV0=
sha1:owa7t8qsfgR7CW0vvNawp1yToP0=
 by: Keith Thompson - Mon, 6 Feb 2023 09:15 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
> On 06.02.2023 05:41, Keith Thompson wrote:
>> Zhao-hui Liu <lllxvs@gmail.com> writes:
>>> On Monday, February 6, 2023 at 9:31:14 AM UTC+8, Keith Thompson wrote:
>>>> I'd suggest `cd /etc/rsyslog.d || exit 1`, so the script indicates that
>>>> it failed.
>>>
>>> `command || exit' is sufficient to indicate script failure, and better
>>> than `command || exit 1', because the latter always returns 1 if
>>> fails, while the former reflects the exit code of command.
>>
>> Good point.
>>
>> I had forgotten that the built-in `exit` command with no arguments uses
>> the exit status of the last command executed. (POSIX specifies this.)
>>
>> If you prefer to be more explicit (as I do), you can use `command || exit $?`.
>
> Notwithstanding there's a point in explicitly specifying an exit code
> (i.e. different from $?), depending on where you come from.
>
> If you think your scripts from a systems perspective you may not be
> interested in the technical reason that $? (or a plain exit) provides;
> you may want to get information from the software process as a whole,
> effectively a process oriented abstraction layer. And the concrete
> command's $? would go into a log file for technical debugging where
> it matters.

Agreed. If all I care about is that the script should die with a
failure status, `exit 1` is probably exactly what I want.

> BTW; what error codes does 'cd' return besides "1"? - The most common
> cases [for me] are non-existing directories, access permissions, and
> file type mismatch, all of them indicated with exit code "1" [in my
> environment] (and differentiated only by the textual output on stderr).

The bash documentation just says:

The return status is zero if the directory is successfully changed,
non-zero otherwise.

POSIX says ">0" if an error occurred.

In practice an error status other than 1 would be mildly surprising.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor