V
V
Vlad_beg2018-04-27 19:53:51
linux
Vlad_beg, 2018-04-27 19:53:51

How to write a bash script that counts the number of commands executed?

When closing the console, it is necessary to display a message with the number of commands executed for the current session, the history command does not work in a bash script, what other options are there?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-04-27
@NeiroNx

Make a variable and plus after each command.

var=$((var+1))
((var=var+1))
((var+=1))
((var++))
let "var=var+1"
let "var+=1"
let "var++"

P
pfg21, 2018-04-27
@pfg21

works, google "getting data from command output" :)
but it's better to read in ~/.bash_history script directly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question