Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Computer programmers never die, they just get lost in the processing.


devel / comp.unix.shell / Re: echoing the last command inside bash function

SubjectAuthor
* Re: echoing the last command inside bash functionKenny McCormack
+* Re: echoing the last command inside bash functionFlash
|+* Re: echoing the last command inside bash functionLew Pitcher
||+* UUOE (Was: echoing the last command inside bash function)Kenny McCormack
|||`- Re: UUOE (Was: echoing the last command inside bash function)Lew Pitcher
||`* Re: echoing the last command inside bash functionFlash
|| `- Re: echoing the last command inside bash functionLew Pitcher
|+- Re: echoing the last command inside bash functionJ.O. Aho
|`* Re: echoing the last command inside bash functionJoe Beanfish
| `- Re: echoing the last command inside bash functionFlash
`* Re: echoing the last command inside bash functionJanis Papanagnou
 `* Re: echoing the last command inside bash functionKenny McCormack
  `- Re: echoing the last command inside bash functionJanis Papanagnou

1
Re: echoing the last command inside bash function

<t9k3gt$28a82$1@news.xmission.com>

  copy mid

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

  copy link   Newsgroups: alt.os.linux comp.unix.shell
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!1.us.feeder.erje.net!feeder.erje.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: alt.os.linux,comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Thu, 30 Jun 2022 12:04:45 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t9k3gt$28a82$1@news.xmission.com>
References: <t9h281$1ta2$1@gioia.aioe.org> <ji5ap2Fc3j3U1@mid.individual.net>
Injection-Date: Thu, 30 Jun 2022 12:04:45 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2369794"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 30 Jun 2022 12:04 UTC

In article <ji5ap2Fc3j3U1@mid.individual.net>,
J.O. Aho <user@example.net> wrote:
....
>> Now instead !! is not rightly evaluated.
>> Why?
>
>For in script you have the history expand by default disabled.
>
>If you want it to be like in command line, then you need to enable the
>history expand
>
>--- bash script ---
>#!/bin/bash
>set -o history -o histexpand
>
>ls /tmp > /dev/null
>echo "CMD='"!:0"'"
>--- eof ---
>
>but it has it's bad sides as you see, you may use trap for better
>debugging, but will not really works as you seems to want and I can't
>see an user case where you would want to do your example.

Two comments:
1) OP has not stated what his actual goal is, so we don't know anything
about what the actual use case is. We may not ever hear back from
OP, so we are left guessing. At least one poster on the thread has
speculated that the goal is to capture the script name so that it
can be used to log file entries and so on. If that is the goal,
then there are many easier, better ways to do that.

2) OP might be looking for $_, which generally holds the name of the
last command executed (at least in bash; don't know about any other
shells). This works in scripts. I sometimes use $_ to tell me
whether or not a loop found a match (i.e., succeeded) or just ended
because the loop ended. For example:

for i in {list of files};do
[ $i matches or whatever ] && break
done
[ $_ = break ] && echo "A match was found!" || echo "Loop exited without finding a match"

--
Watching ConservaLoons playing with statistics and facts is like watching a
newborn play with a computer. Endlessly amusing, but totally unproductive.

Re: echoing the last command inside bash function

<t9kd7h$9qp$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: alt.os.linux comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!mE2H2n/6WJtgtBPTmvRY2w.user.46.165.242.91.POSTED!not-for-mail
From: new@flash.foto (Flash)
Newsgroups: alt.os.linux,comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Thu, 30 Jun 2022 16:50:25 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t9kd7h$9qp$1@gioia.aioe.org>
References: <t9h281$1ta2$1@gioia.aioe.org> <ji5ap2Fc3j3U1@mid.individual.net>
<t9k3gt$28a82$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="10073"; posting-host="mE2H2n/6WJtgtBPTmvRY2w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: it-IT
 by: Flash - Thu, 30 Jun 2022 14:50 UTC

Il 30/06/22 14:04, Kenny McCormack ha scritto:
> OP has not stated what his actual goal is, so we don't know anything
> about what the actual use case is.

$ tree dir | cat >> commands-output

After a few days (in which I will have forgotten what I did exactly, in
which I forgot the command I have in given...)

$ cat commands-output
dir
├── a
├── b
└── c

The output refers to what?
Or rather, Output refers to which command?

So at the first line I would have liked to have the reference command,
and then everything else.

Example

$ cat commands-output
REFERENCE COMMAND: $ tree dir
dir
├── a
├── b
└── c

It can be done?

-----BEGIN PGP MESSAGE-----

hQGMAyHa6HqE1N3qAQwAivFYgm6kp+JCAOLdqF8HrJIEGO/bGqPpxzKGSlBURMAd
tMmrZ5R66x6UhHCfV26+8+4R53A9a0cqCFZdM1imSorGA0A0vRLbz3AQATvR7Cf4
t5/MLKC4v8vHPKU8NA2ny+qaEBuLSPfiidPemqjRN8nLWUqUDh1sxevY8avYNp2L
C8B1uTrDTGSG7Al7D7QacZP00WvfTI8JtgVeG+6aFwEJy+3SLMp/WqFdK18Vp/IL
tgWDyIL1PMvcvA+GFlWCt9P/ULYBOfnqhfvGbkSFCBXwzRRvPxqy0BTARZm2hNRU
4fKHRj++msAW6BihU3kkTq95H/mfAn1RIwIqwX6bF7s/DprdqUtJ5Bx6H79dM6A4
hQyieK3oGdLuWtWxoxLu8akYuwJOJPy9vhqsPGIcTdT3109yg1CUfz+URZaF7HPo
dXKk8fbHVlyhOZ2MrURWxCAjo1ngg3F58Xx1jf3rpXa3xCKHmDLnJUGcYoVd59wh
LeeRHNrGoNr8ST0ipGsF0pYB/QLCDT/aXxIBC31We5eqNhGUgseh8ZqYKfWiU0sj
E90+En2dADXGj5N/UkDr6xMoylDsO94a7FMxQZ07H5UVihYvGBaqtrnU4uMLOGs9
nle7QFLT5toWutoh44bZgeXkMsw1BAzijpg/FByro5pudb9qEum//KTDmGt+HaXd
hjokxZtlFYPOOXmEUQO3XvMnayu+Vt4=
=jI13
-----END PGP MESSAGE-----

Re: echoing the last command inside bash function

<t9kemj$1u4fr$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: alt.os.linux comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: lew.pitcher@digitalfreehold.ca (Lew Pitcher)
Newsgroups: alt.os.linux,comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Thu, 30 Jun 2022 15:15:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <t9kemj$1u4fr$1@dont-email.me>
References: <t9h281$1ta2$1@gioia.aioe.org>
<ji5ap2Fc3j3U1@mid.individual.net> <t9k3gt$28a82$1@news.xmission.com>
<t9kd7h$9qp$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 30 Jun 2022 15:15:31 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="53baa196b23a4863186b4516f6454d5e";
logging-data="2036219"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MVCtv/IThPl9QTtNcL1leNIVouhQ6zVE="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:nRe6XmNAf0BF0ydJXA5YsAoAi1A=
 by: Lew Pitcher - Thu, 30 Jun 2022 15:15 UTC

On Thu, 30 Jun 2022 16:50:25 +0200, Flash wrote:

> Il 30/06/22 14:04, Kenny McCormack ha scritto:
>> OP has not stated what his actual goal is, so we don't know anything
>> about what the actual use case is.
>
> $ tree dir | cat >> commands-output

UUOC. Try
tree dir >>commands-output
instead

>
> After a few days (in which I will have forgotten what I did exactly, in
> which I forgot the command I have in given...)
>
> $ cat commands-output
> dir
> ├── a
> ├── b
> └── c
>
> The output refers to what?
> Or rather, Output refers to which command?
>
> So at the first line I would have liked to have the reference command,
> and then everything else.
[snip]
> It can be done?

Yes

Try
echo "tree dir" | script -a commands-output

See script(1) ("man 1 script") for details

> -----BEGIN PGP MESSAGE-----
[snip]
> -----END PGP MESSAGE-----
And, why the encrypted message?

HTH
--
Lew Pitcher
"In Skills, We Trust"

UUOE (Was: echoing the last command inside bash function)

<t9kg5o$28hd0$1@news.xmission.com>

  copy mid

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

  copy link   Newsgroups: alt.os.linux comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: alt.os.linux,comp.unix.shell
Subject: UUOE (Was: echoing the last command inside bash function)
Date: Thu, 30 Jun 2022 15:40:40 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t9kg5o$28hd0$1@news.xmission.com>
References: <t9h281$1ta2$1@gioia.aioe.org> <t9k3gt$28a82$1@news.xmission.com> <t9kd7h$9qp$1@gioia.aioe.org> <t9kemj$1u4fr$1@dont-email.me>
Injection-Date: Thu, 30 Jun 2022 15:40:40 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2377120"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 30 Jun 2022 15:40 UTC

In article <t9kemj$1u4fr$1@dont-email.me>,
Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
....
>Try
> echo "tree dir" | script -a commands-output

At least in principle: script -a commands-output <<< "tree dir"
But I actually don't know if script reads from stdin like this anyway.

So:

script -ac "tree dir" commands-output

Note: I do endorse using script for this. A useful command that many don't
know about.

--
To most Christians, the Bible is like a software license. Nobody
actually reads it. They just scroll to the bottom and click "I agree."

- author unknown -

Re: UUOE (Was: echoing the last command inside bash function)

<t9kh9f$1u4fr$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: alt.os.linux comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: lew.pitcher@digitalfreehold.ca (Lew Pitcher)
Newsgroups: alt.os.linux,comp.unix.shell
Subject: Re: UUOE (Was: echoing the last command inside bash function)
Date: Thu, 30 Jun 2022 15:59:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 89
Message-ID: <t9kh9f$1u4fr$2@dont-email.me>
References: <t9h281$1ta2$1@gioia.aioe.org>
<t9k3gt$28a82$1@news.xmission.com> <t9kd7h$9qp$1@gioia.aioe.org>
<t9kemj$1u4fr$1@dont-email.me> <t9kg5o$28hd0$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 30 Jun 2022 15:59:43 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="53baa196b23a4863186b4516f6454d5e";
logging-data="2036219"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kDfXmJ0PxzAuQ8dbAJwsbZuk+4nK8Alw="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:x3brGDtNlrq+0+ffpOaFeNCDcmM=
 by: Lew Pitcher - Thu, 30 Jun 2022 15:59 UTC

On Thu, 30 Jun 2022 15:40:40 +0000, Kenny McCormack wrote:

> In article <t9kemj$1u4fr$1@dont-email.me>,
> Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
> ...
>>Try
>> echo "tree dir" | script -a commands-output
>
> At least in principle: script -a commands-output <<< "tree dir"
> But I actually don't know if script reads from stdin like this anyway.
>
> So:
>
> script -ac "tree dir" commands-output

Nope. The OP "... would have liked to have the reference command,
and then everything else." script -c does /not/ write the command
into the typescript file.

11:53 $ cat tree_ac.txt
cat: tree_ac.txt: No such file or directory

11:54 $ script -ac "tree tmp" tree_ac.txt
Script started, file is tree_ac.txt
tmp
|-- a.out
|-- tst
`-- tst.c

0 directories, 3 files
Script done, file is tree_ac.txt

11:54 $ cat tree_ac.txt
Script started on Thu 30 Jun 2022 11:54:09 AM EDT
tmp
|-- a.out
|-- tst
`-- tst.c

0 directories, 3 files

Script done on Thu 30 Jun 2022 11:54:09 AM EDT
11:54 $

But
echo "command" | script
/does/ write the command into the typescript file

11:56 $ cat tree_a.txt
cat: tree_a.txt: No such file or directory

11:56 $ echo "tree tmp" | script -a tree_a.txt
Script started, file is tree_a.txt
tree tmp
11:56 $ tree tmp
tmp
|-- a.out
|-- tst
`-- tst.c

0 directories, 3 files
11:56 $ exit
Script done, file is tree_a.txt

11:56 $ cat tree_a.txt
Script started on Thu 30 Jun 2022 11:56:30 AM EDT
tree tmp
11:56 $ tree tmp
tmp
|-- a.out
|-- tst
`-- tst.c

0 directories, 3 files

11:56 $

Script done on Thu 30 Jun 2022 11:56:30 AM EDT
11:56 $

> Note: I do endorse using script for this. A useful command that many don't
> know about.

--
Lew Pitcher
"In Skills, We Trust"

Re: echoing the last command inside bash function

<t9ki66$kvi$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: alt.os.linux comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!mE2H2n/6WJtgtBPTmvRY2w.user.46.165.242.91.POSTED!not-for-mail
From: new@flash.foto (Flash)
Newsgroups: alt.os.linux,comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Thu, 30 Jun 2022 18:15:02 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t9ki66$kvi$1@gioia.aioe.org>
References: <t9h281$1ta2$1@gioia.aioe.org> <ji5ap2Fc3j3U1@mid.individual.net>
<t9k3gt$28a82$1@news.xmission.com> <t9kd7h$9qp$1@gioia.aioe.org>
<t9kemj$1u4fr$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="21490"; posting-host="mE2H2n/6WJtgtBPTmvRY2w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: it-IT
 by: Flash - Thu, 30 Jun 2022 16:15 UTC

Il 30/06/22 17:15, Lew Pitcher ha scritto:
> [...]
$ rm typescript
$ echo "tree" | script | cat -n
1 Script iniziato, il file è typescript
2 tree
3 $ tree
4 .
5 ├── file1
6 ├── file2
7 └── typescript
8
9 0 directories, 3 files
10 $ exit
11 Script effettuato, il file è typescript
$ test -f typescript && echo FILE FOUND
FILE FOUND

I want to send the output only to the "cat -n" command and not to the
typescript file.

Re: echoing the last command inside bash function

<t9kk0u$1v7i7$1@dont-email.me>

  copy mid

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

  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@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Thu, 30 Jun 2022 18:46:22 +0200
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <t9kk0u$1v7i7$1@dont-email.me>
References: <t9h281$1ta2$1@gioia.aioe.org> <ji5ap2Fc3j3U1@mid.individual.net>
<t9k3gt$28a82$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 30 Jun 2022 16:46:22 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="c37ddceecd727cda234f0b57f77be337";
logging-data="2072135"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dIhmhSZSojyfN0szaiOA5"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:Gq+WoIwrMuY0yld7M2BFFaM/Pi0=
In-Reply-To: <t9k3gt$28a82$1@news.xmission.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Thu, 30 Jun 2022 16:46 UTC

On 30.06.2022 14:04, Kenny McCormack wrote:
>
> 2) OP might be looking for $_, which generally holds the name of the
> last command executed (at least in bash;

Does it? - In ksh $_ keeps the last word of the previous command line,
so 'break' or 'ls' will return the command name (incidentally), and
'ls a b c' will return 'c'. - A quick bash test seems to indicate that
it behaves like ksh in that respect.

> don't know about any other
> shells). This works in scripts. I sometimes use $_ to tell me
> whether or not a loop found a match (i.e., succeeded) or just ended
> because the loop ended. For example:
>
> for i in {list of files};do
> [ $i matches or whatever ] && break
> done
> [ $_ = break ] && echo "A match was found!" || echo "Loop exited without finding a match"
>

Wouldn't that be enough...?

for i in {list of files};do
[ $i matches or whatever ] && break
done && echo "A match was found!" || echo "Loop exited without finding
a match"

(works at least in ksh)

Janis

Re: echoing the last command inside bash function

<ji65j3Fgd0gU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: alt.os.linux comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (J.O. Aho)
Newsgroups: alt.os.linux,comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Thu, 30 Jun 2022 19:41:55 +0200
Lines: 41
Message-ID: <ji65j3Fgd0gU1@mid.individual.net>
References: <t9h281$1ta2$1@gioia.aioe.org> <ji5ap2Fc3j3U1@mid.individual.net>
<t9k3gt$28a82$1@news.xmission.com> <t9kd7h$9qp$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net V4X94V9l9+6YPAXmVgts2Qz9bTl5m+teW7OKBtr5P7nuU7xG/X
Cancel-Lock: sha1:IFFbbS2fKPZvqqh55I1L4YJ6flU=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Content-Language: en-US-large
In-Reply-To: <t9kd7h$9qp$1@gioia.aioe.org>
 by: J.O. Aho - Thu, 30 Jun 2022 17:41 UTC

On 30/06/2022 16.50, Flash wrote:
> Il 30/06/22 14:04, Kenny McCormack ha scritto:
>>  OP has not stated what his actual goal is, so we don't know anything
>>     about what the actual use case is.
>
> $ tree dir | cat >> commands-output
>
> After a few days (in which I will have forgotten what I did exactly, in
> which I forgot the command I have in given...)

so you want something like:

--- runcmd ---
#!/bin/bash
CMD=$1
echo "$CMD"
eval $CMD
--- eof ---

runcmd "tree /dir" >> commands-output

Maybe better to bookmark the webpage where you found the command line in
the first place ;)

history is a good command to get to know what you done before and you
can add time stamp to it too

https://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/

other alternatives:
- use more describing file names so you know what the content is and
how to regenerate it
- Use bash audit and look in the logs.
- make a script that does your work and can add a comment what input
parameters was used

--
//Aho

Re: echoing the last command inside bash function

<t9kufm$1u4fr$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: alt.os.linux comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: lew.pitcher@digitalfreehold.ca (Lew Pitcher)
Newsgroups: alt.os.linux,comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Thu, 30 Jun 2022 19:44:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <t9kufm$1u4fr$3@dont-email.me>
References: <t9h281$1ta2$1@gioia.aioe.org>
<ji5ap2Fc3j3U1@mid.individual.net> <t9k3gt$28a82$1@news.xmission.com>
<t9kd7h$9qp$1@gioia.aioe.org> <t9kemj$1u4fr$1@dont-email.me>
<t9ki66$kvi$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 30 Jun 2022 19:44:54 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="53baa196b23a4863186b4516f6454d5e";
logging-data="2036219"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iI0BgdMZ0lxWP6ey8R9pLkHtNhSuaX5o="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:ea59mTAFgR/1jYVbi7uXEgqLtis=
 by: Lew Pitcher - Thu, 30 Jun 2022 19:44 UTC

On Thu, 30 Jun 2022 18:15:02 +0200, Flash wrote:

[snip]
> I want to send the output only to the "cat -n" command and not to the
> typescript file.

Ahhh. But that's /not/ what you said in the post I replied to

On Thu, 30 Jun 2022 16:50:25 +0200, Flash wrote:
Flash> $ tree dir | cat >> commands-output
Flash>
Flash> After a few days (in which I will have forgotten what I did exactly, in
Flash> which I forgot the command I have in given...)
...
Flash>
Flash> So at the first line I would have liked to have the reference command,
Flash> and then everything else.

You didn't say that you wanted the data line-numbered

Anyway, I answered the question you asked.
--
Lew Pitcher
"In Skills, We Trust"

Re: echoing the last command inside bash function

<t9mt2b$28vn6$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: alt.os.linux comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: joebeanfish@nospam.duh (Joe Beanfish)
Newsgroups: alt.os.linux,comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Fri, 1 Jul 2022 13:32:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <t9mt2b$28vn6$1@dont-email.me>
References: <t9h281$1ta2$1@gioia.aioe.org> <ji5ap2Fc3j3U1@mid.individual.net>
<t9k3gt$28a82$1@news.xmission.com> <t9kd7h$9qp$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 1 Jul 2022 13:32:59 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="d61ed0cf99e6a3bfff81c41efae7efb3";
logging-data="2391782"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cvZXo6rxxmB2URSY5jcUtrCfV/+6qzuY="
User-Agent: Pan/0.146 (Hic habitat felicitas; 8107378
git@gitlab.gnome.org:GNOME/pan.git)
Cancel-Lock: sha1:zRgwsBRB6wFczPau5+z0KzMMzIA=
 by: Joe Beanfish - Fri, 1 Jul 2022 13:32 UTC

On Thu, 30 Jun 2022 16:50:25 +0200, Flash wrote:

> Il 30/06/22 14:04, Kenny McCormack ha scritto:
>> OP has not stated what his actual goal is, so we don't know anything
>> about what the actual use case is.
>
> $ tree dir | cat >> commands-output
>
> After a few days (in which I will have forgotten what I did exactly, in
> which I forgot the command I have in given...)
>
> $ cat commands-output
> dir
> ├── a
> ├── b
> └── c
>
> The output refers to what?
> Or rather, Output refers to which command?
>
> So at the first line I would have liked to have the reference command,
> and then everything else.
>
> Example
>
> $ cat commands-output
> REFERENCE COMMAND: $ tree dir
> dir
> ├── a
> ├── b
> └── c
>
> It can be done?

(set -x; tree a) >commands-output 2>&1

Re: echoing the last command inside bash function

<t9n6cj$29svm$1@news.xmission.com>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Fri, 1 Jul 2022 16:12:03 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t9n6cj$29svm$1@news.xmission.com>
References: <t9h281$1ta2$1@gioia.aioe.org> <ji5ap2Fc3j3U1@mid.individual.net> <t9k3gt$28a82$1@news.xmission.com> <t9kk0u$1v7i7$1@dont-email.me>
Injection-Date: Fri, 1 Jul 2022 16:12:03 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2421750"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 1 Jul 2022 16:12 UTC

In article <t9kk0u$1v7i7$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>On 30.06.2022 14:04, Kenny McCormack wrote:
>>
>> 2) OP might be looking for $_, which generally holds the name of the
>> last command executed (at least in bash;
>
>Does it? - In ksh $_ keeps the last word of the previous command line,
>so 'break' or 'ls' will return the command name (incidentally), and
>'ls a b c' will return 'c'. - A quick bash test seems to indicate that
>it behaves like ksh in that respect.

What can I say? It works for me.

Two comments:
1) The test should actually be:
[ X$_ = Xbreak ] && echo "It broke!"
since otherwise you have a problem if $_ is empty (which I think it
will be if you exit the loop "normally").

2) My actual use case was a little more complicated than the "distilled
down for posting to Usenet" version, and I was having problems
getting it to work reliably doing it your way. In general, I'm not
real comfortable with relying on "default" exit statuses (i.e.,
those not explicitly set in code).

But, anyway, it works for me. That's all that matters.

--
People who want to share their religious views with you
almost never want you to share yours with them. -- Dave Barry

Re: echoing the last command inside bash function

<t9n8hc$i4d$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: alt.os.linux comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!mE2H2n/6WJtgtBPTmvRY2w.user.46.165.242.91.POSTED!not-for-mail
From: new@flash.foto (Flash)
Newsgroups: alt.os.linux,comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Fri, 1 Jul 2022 18:48:44 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t9n8hc$i4d$1@gioia.aioe.org>
References: <t9h281$1ta2$1@gioia.aioe.org> <ji5ap2Fc3j3U1@mid.individual.net>
<t9k3gt$28a82$1@news.xmission.com> <t9kd7h$9qp$1@gioia.aioe.org>
<t9mt2b$28vn6$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="18573"; posting-host="mE2H2n/6WJtgtBPTmvRY2w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: it-IT
 by: Flash - Fri, 1 Jul 2022 16:48 UTC

Il 01/07/22 15:32, Joe Beanfish ha scritto:
> (set -x; tree a) >commands-output 2>&1

buona idea

Re: echoing the last command inside bash function

<t9n8ue$2ah7k$1@dont-email.me>

  copy mid

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

  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@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: echoing the last command inside bash function
Date: Fri, 1 Jul 2022 18:55:41 +0200
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <t9n8ue$2ah7k$1@dont-email.me>
References: <t9h281$1ta2$1@gioia.aioe.org> <ji5ap2Fc3j3U1@mid.individual.net>
<t9k3gt$28a82$1@news.xmission.com> <t9kk0u$1v7i7$1@dont-email.me>
<t9n6cj$29svm$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Jul 2022 16:55:42 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="78db6ecea1883e4958845b111b6eb677";
logging-data="2442484"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yZHXcx5TtmSsMZIZVpnWJ"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:3FVy0RhObMqqdALC82267501q2o=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <t9n6cj$29svm$1@news.xmission.com>
 by: Janis Papanagnou - Fri, 1 Jul 2022 16:55 UTC

On 01.07.2022 18:12, Kenny McCormack wrote:
> In article <t9kk0u$1v7i7$1@dont-email.me>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>> On 30.06.2022 14:04, Kenny McCormack wrote:
>>>
>>> 2) OP might be looking for $_, which generally holds the name of the
>>> last command executed (at least in bash;
>>
>> Does it? - In ksh $_ keeps the last word of the previous command line,
>> so 'break' or 'ls' will return the command name (incidentally), and
>> 'ls a b c' will return 'c'. - A quick bash test seems to indicate that
>> it behaves like ksh in that respect.
>
> What can I say? It works for me.

I just wanted to point out that as soon as you have a command with
arguments it won't work any more; because the assumption that $_
would contain the command name was obviously wrong.

>
> Two comments:
> 1) The test should actually be:
> [ X$_ = Xbreak ] && echo "It broke!"
> since otherwise you have a problem if $_ is empty (which I think it
> will be if you exit the loop "normally").
>
> 2) My actual use case was a little more complicated than the "distilled
> down for posting to Usenet" version, and I was having problems
> getting it to work reliably doing it your way.

I considered that possibility, was sure you'll point that out if so.

> In general, I'm not
> real comfortable with relying on "default" exit statuses (i.e.,
> those not explicitly set in code).

I see. Same here, but then I'd prefer setting and testing a flag
explicitly.

Janis

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor