Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Strange bash question

  • 08-09-2012 10:45pm
    #1
    Closed Accounts Posts: 18,966 ✭✭✭✭


    Ok, this is a minor annoyance which I run into now and again I wondered if anyone had a solution. I've trawled man pages and docs, but not found an answer.

    At my normal bash prompt, if I use the up arrow key, I get to scroll through the history buffer. Using the down arrow brings me back to a blank bash prompt, which is fine.

    What I find myself doing occasionally, is typing a long command, and as I am about to finish it, I realise I forgot a previous step, and now want a fresh prompt in which to run that missing command. What I would like to do is press down arrow to get a 'fresh' prompt, but that does not work out of the box.

    Anyone have any ideas?


Comments

  • Registered Users, Registered Users 2 Posts: 14,048 ✭✭✭✭Johnboy1951


    syklops wrote: »
    Ok, this is a minor annoyance which I run into now and again I wondered if anyone had a solution. I've trawled man pages and docs, but not found an answer.

    At my normal bash prompt, if I use the up arrow key, I get to scroll through the history buffer. Using the down arrow brings me back to a blank bash prompt, which is fine.

    What I find myself doing occasionally, is typing a long command, and as I am about to finish it, I realise I forgot a previous step, and now want a fresh prompt in which to run that missing command. What I would like to do is press down arrow to get a 'fresh' prompt, but that does not work out of the box.

    Anyone have any ideas?

    Normal behaviour here too.

    Use a separate terminal to do the command you forgot?

    Use split screen to do the other command? EDIT nope, doesn't work here ..... I get a duplicate screen rather than two separate screens.

    Ah yes ....... new tab for second command does it! :D


  • Registered Users, Registered Users 2 Posts: 200 ✭✭druidhill


    Ctrl+C


  • Registered Users, Registered Users 2 Posts: 14,048 ✭✭✭✭Johnboy1951


    druidhill wrote: »
    Ctrl+C

    That loses the long command that has been typed in .... I thought the idea was to retain it so it did not need to be typed again .......


  • Registered Users, Registered Users 2 Posts: 218 ✭✭Tillotson


    I usually just kill the current line: C-a C-k
    Enter the command I've missed
    Then paste the killed line back in: C-y


  • Registered Users, Registered Users 2 Posts: 453 ✭✭Ant


    Tillotson wrote: »
    I usually just kill the current line: C-a C-k
    Enter the command I've missed
    Then paste the killed line back in: C-y

    I'd use a similar technique with the difference that I prefer the vi key-bindings (set -o vi).
    • ESC dd (move all the typed command into buffer and clear the line)
    • i <extra command> RET (type the new command and run it)
    • ESC p (paste the previous command)


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 62 ✭✭LiamOSullivan


    The vi keybinding is a nice way to do it, but it'll drive you nuts unless you use vi to edit text usually.

    You could always just move to the start os the line(ctrl+a) and add your command before what you have, using &&.

    Let's say you've just typed out
    cd /to/this/really/long/directory/path/with/lots\ of\ annoying/parts/to/your/porn/
    
    but you realise that you've forgotten to mount the partition with your porn on it.
    No worries!
    mount /dev/porn /to/this/really/.../ && cd /to/this/really/.../
    


  • Closed Accounts Posts: 18,966 ✭✭✭✭syklops


    Thanks Liam, thats what I have been doing. I was hoping for a more elegant way.

    Incidentally, its not porn, but a lot of the time it is mounting drives and moving media files, often containing spaces and special characters.


  • Registered Users, Registered Users 2 Posts: 62 ✭✭LiamOSullivan


    Tab completion is fantastic for those crazy directory names, but other than that, vi keybindings is probably the most elegant way.


  • Closed Accounts Posts: 18,966 ✭✭✭✭syklops


    Tab completion is fantastic for those crazy directory names, but other than that, vi keybindings is probably the most elegant way.

    Yeah I nearly wet myself the day I discovered tab-completion. I don't want to do use the vi key bindings, because I work on a myriad of different systems, and I've done it before where I set up some funky key binding, or some cool alias, and get used to it, and then go on a server that doesnt have that customisation, and then I start to miss it and have to get used to life with out it again.

    Ctrl-a, ctrk-k and then ctrl-y is the way to go I think.


  • Registered Users, Registered Users 2 Posts: 218 ✭✭Tillotson


    Check out `man readline`for a plethora editing commands.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    I hit home, #, enter. (effectively commenting out the current command) run my new command, then use up arrow and remove the hash and continue on. Works grand.

    More often than not I'll use a new window though. I have a keyboard shortcut to fire up a terminal C-A-n (and there is C-S-n within the gnome terminal too).


  • Registered Users, Registered Users 2 Posts: 62 ✭✭LiamOSullivan


    Khannie wrote: »
    I hit home, #, enter. (effectively commenting out the current command) run my new command, then use up arrow and remove the hash and continue on. Works grand.
    :eek:
    I like this.


  • Closed Accounts Posts: 18,966 ✭✭✭✭syklops


    Khannie wrote: »
    I hit home, #, enter. (effectively commenting out the current command) run my new command, then use up arrow and remove the hash and continue on. Works grand.

    More often than not I'll use a new window though. I have a keyboard shortcut to fire up a terminal C-A-n (and there is C-S-n within the gnome terminal too).

    Thats kind of cool! I can start a new terminal usually with Ctrl+T, but if im running the command as root, then I need to su - which is not elegant. Must try your way.

    Just tried it, Ooooh thats pretty awesome. Thanks for that!


  • Closed Accounts Posts: 18,966 ✭✭✭✭syklops


    OSI wrote: »
    You could always home to the start of the command you've typed, type in the command you forgot and end it with a semi-colon ; and a space before the command you originally type and the terminal will run them in order.

    eg
    first command
    
    forgotten command; first command
    

    Yeah I tried that, but I use the history alot and like to rerun commands from it. Inserting the forgotten command and a semi-colon can not always be desirable. Khannie's # trick looks like the winner.


  • Registered Users, Registered Users 2 Posts: 5,238 ✭✭✭humbert


    Ant wrote: »
    I'd use a similar technique with the difference that I prefer the vi key-bindings (set -o vi).
    • ESC dd (move all the typed command into buffer and clear the line)
    • i <extra command> RET (type the new command and run it)
    • ESC p (paste the previous command)
    Can't believe I didn't know about this.


  • Registered Users, Registered Users 2 Posts: 453 ✭✭Ant


    humbert wrote: »
    Can't believe I didn't know about this.

    Yeah. I was delighted when I discovered I could use all the vi commands that have become second nature in any OS with a bash shell (GNU/Linux, BSD, OS X, Cygwin). I only recently discovered that info (the official documentation for many GNU programs) also has a vi mode.

    This thread is a great example of there being more than one (elegant) way to accomplish a task in *nix.


  • Closed Accounts Posts: 18,966 ✭✭✭✭syklops


    Ant wrote: »
    I'd use a similar technique with the difference that I prefer the vi key-bindings (set -o vi).
    • ESC dd (move all the typed command into buffer and clear the line)
    • i <extra command> RET (type the new command and run it)
    • ESC p (paste the previous command)

    ZOMG!!11! I just tried that now and it works. Thats awesome aswell!

    I love Linux / Unix :D


  • Registered Users, Registered Users 2 Posts: 1,333 ✭✭✭Saganist


    Hi.

    Try using zsh instead of bash.

    It's like bash on steroids. I've been using it over bash for ages now and would never go back.


  • Closed Accounts Posts: 18,966 ✭✭✭✭syklops


    Saganist wrote: »
    Hi.

    Try using zsh instead of bash.

    It's like bash on steroids. I've been using it over bash for ages now and would never go back.

    Thanks for the advice, but because I work on such a wide variety of servers, I try to stick to standard tools as much as possible, and make them work as much as possible. Its why I didnt want to solve this problem with a custom key binding. Otherwise the result is i log into a work-related server or customers server, and go to utilise my special trick, or tool or whatever, and its not there and i can't install it, and then I miss it.

    I will check out zsh at home though.


  • Registered Users, Registered Users 2 Posts: 1,333 ✭✭✭Saganist


    syklops wrote: »
    Thanks for the advice, but because I work on such a wide variety of servers, I try to stick to standard tools as much as possible, and make them work as much as possible. Its why I didnt want to solve this problem with a custom key binding. Otherwise the result is i log into a work-related server or customers server, and go to utilise my special trick, or tool or whatever, and its not there and i can't install it, and then I miss it.

    I will check out zsh at home though.

    Give it is a bash. lol

    It is mostly backward compatible with bash scripts.


  • Advertisement
Advertisement