Re: [SLUG] Re: useful bash tricks thread
At the risk of being called an oldie, I keep using !-notation since the early tcsh days. E.g. !$ or !:2-3. You can also use things like !less:* to fetch the parameters of the latest less command. I can't type alt- because alt-shift is my keyboard language-switching combination, so I don't know how this compares with good old bang-notation. Other useful stuff: ^x^y will replace the first x on the previous line by y. Use a third ^ after y if it contains space. It's actually a short for !!:s/x/y/ Where !!:s comes handy is to replace globally: !!gs/x/y/ will replace ALL of the x's on last line by y's. Then again - you can type !command or !-3 to use another history line as a basis. And one last thing, related to security - if you type a sensitive string on the command line and get it into your history, use history -d to delete this line. Cheers, --Amos -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] Re: useful bash tricks thread
2009/2/9 Amos Shapira amos.shap...@gmail.com: [snip] And one last thing, related to security - if you type a sensitive string on the command line and get it into your history, use history -d to delete this line. There is an easier way around this. Most shells, bash included will exclude a line from the history if you begin it with a space. cheers, Owen. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] Re: useful bash tricks thread
Owen Townend wrote: 2009/2/9 Amos Shapira amos.shap...@gmail.com: [snip] And one last thing, related to security - if you type a sensitive string on the command line and get it into your history, use history -d to delete this line. There is an easier way around this. Most shells, bash included will exclude a line from the history if you begin it with a space. My bash doesn't do this. It includes the line in the history :( but HISTSIZE=2000 SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor might have an effect on this behaviour. cheer rickw -- _ Rick Welykochy || Praxis Services If you have any trouble sounding condescending, find a Unix user to show you how it's done. -- Scott Adams -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] Re: useful bash tricks thread
2009/2/9 Amos Shapira amos.shap...@gmail.com At the risk of being called an oldie, I keep using !-notation since the early tcsh days. E.g. !$ or !:2-3. You can also use things like !less:* to fetch the parameters of the latest less command. I can't type alt- because alt-shift is my keyboard language-switching combination, so I don't know how this compares with good old bang-notation. Other useful stuff: ^x^y will replace the first x on the previous line by y. Use a third ^ after y if it contains space. It's actually a short for !!:s/x/y/ ... I knew it. I knew there were more of you out there! :) That whole bang/caret substitute-a-pattern-and-then-run thing just scares me though, plus its hard to type. I'll stick with ctrl-r and vi-mode. But interesting... -- Daniel Bush -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] Re: useful bash tricks thread
2009/2/9 Rick Welykochy r...@praxis.com.au: Owen Townend wrote: 2009/2/9 Amos Shapira amos.shap...@gmail.com: [snip] And one last thing, related to security - if you type a sensitive string on the command line and get it into your history, use history -d to delete this line. There is an easier way around this. Most shells, bash included will exclude a line from the history if you begin it with a space. My bash doesn't do this. It includes the line in the history :( but HISTSIZE=2000 SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor might have an effect on this behaviour. Ah, my default bashrc has HISTCONTROL set. ~$ echo $HISTCONTROL ignoreboth This sets ignorespace and ignoredups, see the man page for details. cheers, Owen. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
[SLUG] Re: useful bash tricks thread
On Feb 6, 9:06 pm, Tony Sceats t...@fatuous.org wrote: It's been a while since there's been a thread like this, so I thought it would be fun :) so, have you got any? I've got 2 to share today: alt and then alt woo, that's kinda interesting. It seems to pick the last word for each entry in the command-line history? Definitely second ctrl-r; I can't imagine a world without it.. Well i can, I used to work with an older unix guy who used some older version of bourne or c-shell and used !pattern (something like that) to run previous commands. No, never again. Mind you, I set my shell to use vi mode (set -o vi) which I think would freak out a lot of people. I often have several files of related commands that I source into my current shell. This isn't a trick, more a set of conventions which I've found useful to help keep me on top of things. eg % . some_file.sh This file would have the following format: h() { less -EOF VAR1: $VAR1 VAR2: $VAR2 ... func1 - do X func2 - do Y EOF } VAR1=some_val1 VAR2=some_val2 ... func1() { ... } func2() { ... } Then you can simply do: % func1 ... to run your routine. % h will list the commands and their descriptions assuming you've documented them. There are number of plain words you can use for your function names: go,show,build,change,list,check,log,update,start,stop etc You might do this to parcel up a bunch of related commands for some area or thing. For instance, managing a database. 'go' might take you to conf directory or put you into the database shell etc etc It's also a good place to stash notes if you're learning something or documenting it - either as comments or in the h() or simply in the functions themselves. Listing things like relevant locations and filenames as shell VARS is good documentation too. My other even more OT tip: if you use the commandline a lot and you haven't tried screen, try it and become the super nerd you were always meant to be. -- Daniel Bush -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] Re: useful bash tricks thread
On Sat, Feb 7, 2009 at 11:58 PM, Daniel Bush dlb.id...@gmail.com wrote: On Feb 6, 9:06 pm, Tony Sceats t...@fatuous.org wrote: It's been a while since there's been a thread like this, so I thought it would be fun :) so, have you got any? I've got 2 to share today: alt and then alt woo, that's kinda interesting. It seems to pick the last word for each entry in the command-line history? yep, kinda like !$, but this is an interactive search on the last argument to previous commands, instead of just static 'last argument to last command' -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html