X
X
xotkot2014-05-08 19:33:54
linux
xotkot, 2014-05-08 19:33:54

How to find out the name of the previous command in a script?

There is a special bash variable "$_" which contains the last argument of the previous command. But how to get the whole previous command in a script?
for example:

#!/usr/bin/env zsh

fn() {
    pre_command=...
    echo $pre_command   # выводит "date -I"
}

date -I
fn

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan Donin, 2014-05-09
@xotkot

Didn't check but!! works? Or 2.
upd: problem solution below

N
Nikolay Shamanovich, 2014-05-08
@Shm13

MB through history pull out. So offhand said.

I
Ingtar, 2014-05-09
@Ingtar

superuser.com/questions/453363/return-last-command...
Not helping?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question