perform commands on previous bash commands

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

perform commands on previous bash commands

#1 Post by sc0ttman »

what is the easiest way, using bash, to perform commands on a given number of previously run bash commands..

for example: maybe I want to add

Code: Select all

>> /tmp/myhowtocmds
to the end of the last 10 or 15 bash commands, and run them all again, to create a log of the commands...

this is just an example, and other the specific uses are not so important - I just want an efficient way to loop through my previous bash commands and run another command on them.

amny help would be great, I looked around, but couldn't find what I wanted...
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
Dingo
Posts: 1437
Joined: Tue 11 Dec 2007, 17:48
Location: somewhere at the end of rainbow...
Contact:

#2 Post by Dingo »

a rough but working solution

assuming to recall last n history entries, you can join with other commands and then paste in a file you make executable

Code: Select all

history 2 >1.txt && printf '>> /tmp/myhowtocmds\n%.0s' {1..2} >2.txt && paste 1.txt 2.txt>3.txt && sed -e '1i\#!/bin/sh' 3.txt >addlog && chmod +x addlog
with this code you:

- recall last 2 history commands (and store in 1.txt)
- write n times (2 in this case) the commands you want add and store in 2.txt)
- paste 1.txt and 2.txt (merging lines) in 3.txt
- add at first line of 3.txt the Shebang char
- write content of 3.txt in another file and make this executable with chmod

now you can launch script created
replace .co.cc with .info to get access to stuff I posted in forum
dropbox 2GB free
OpenOffice for Puppy Linux

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#3 Post by big_bass »

My keyboard isnt working so I will be keep it simple the last 15 commands you typed are in
/root/.history so an edit box opens and lets you add code however you want to when done select ok your new code gets saved here /tmp/myhowtocmds_edit

the script I attached should be used just by clicking on it (dont fill up the history by selecting the code snippet and pasting it
you will miss the point of what it does
showing you your last 15 bash commands in the terminal

Joe

Code: Select all

#!/bin/sh
:>/tmp/myhowtocmds 
:>/tmp/myhowtocmds_edit 
tail  -15  /root/.history>> /tmp/myhowtocmds 



# Joe Arose 
# version 1
# edit   /root/.history
# small editor 
# quick and easy if you want just a viewer select "cancel" no changes

# if you edit the file and want to save it with the name /tmp/myhowtocmds_edit
# select "ok" 

# depends on Xdialog gtk1 or gtk2



Xdialog --title "Micro edit box" --fixed-font "" \
	--editbox /tmp/myhowtocmds 0 0 2>/tmp/myhowtocmds_edit 

case $? in
  0)
    
    #echo "OK"
    ;;
  1)
    echo "Cancel pressed."
    ;;
  255)
    echo "Box closed."
    ;;
esac
Attachments
how2cli.gz
(358 Bytes) Downloaded 248 times

Post Reply