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

0 like 0 dislike
4 views
Necessary when closing the console will display a message with the number of performed commands for the current session, the history command does not work in bash script, what are the other options?
by | 4 views

2 Answers

0 like 0 dislike
Make a variable and put it in after each command.
var=$((var+1)) ((var=var+1)) ((var+=1)) ((var++)) let "var=var+1" let "var+=1" let "var++"
by
0 like 0 dislike
works, Google "getting data from command output" :)

but it is better to read in the script ~/.bash_history directly.
by

Related questions

0 like 0 dislike
4 answers
asked Apr 9, 2019 by aleksmanson
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
33,652 users