[SOLVED] What's an easy way to edit a multiline bash command?

3 years ago by deepdive to c/linux

Hello there :)

As far as I know (searched through the web), editing/navigating a multiline in bash is not possible and opening nano, pasting and editing is to much friction I want to get rid off.

Do you have any way to speed up the process?

example of multiline:

echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Thank you :)

parasrah 7 points 3 years ago

You can use C-x C-e in bash to open the current line in $EDITOR and edit it there. Much faster than copying and pasting :)

path: 0 99841, hotness: undefined, score: 7, children: 2
deepdive 1 point 3 years ago

Thank you :) Helps alot !!

path: 0 99841 104477, hotness: undefined, score: 1, children: 0
INeedMana 1 point 3 years ago path: 0 99841 107117, hotness: undefined, score: 1, children: 0
gartheom 5 points 3 years ago

As soon as a bash command gets to multiple lines, i save it as a bash script and then edit it in a text editor.

path: 0 95015, hotness: undefined, score: 5, children: 1
deepdive 1 point 3 years ago

Thank you for your response :) But that's actually what I don't want to do...

It’s not about looking pretty, I like to navigate freely like CTRL-E, CTRL-A, ALT-B, ALT-F… speeds up the process and is frictionless (like your link suggests it :P). Sometimes I copy/past an already written command in the CLI with multilines and not being able to navigate thourgh them is frustrating !

path: 0 95015 96128, hotness: undefined, score: 1, children: 0
taaz 5 points 3 years ago

Ctrl+x Ctrl+e

path: 0 95020, hotness: undefined, score: 5, children: 1
deepdive 1 point 3 years ago

Hey :) Thank you !! That's not exactly what I hoped for but it does the trick very smoothly !!!!

path: 0 95020 98534, hotness: undefined, score: 1, children: 0
nii236 2 points 3 years ago

You can use the emacs shortcuts to navigate quickly, jump forward or backwards over words or to the start or end of a line.

path: 0 98083, hotness: undefined, score: 2, children: 3
deepdive 1 point 3 years ago

Hey thank you :) I didn't knew these shortcuts where called emacs ! As @taaz said Ctrl+x Ctrl-e is probably the best I will get.

path: 0 98083 98498, hotness: undefined, score: 1, children: 2
nii236 1 point 3 years ago
  • Ctrl-A (jump to beginning of line)
  • Ctrl-E (jump to end of line)
  • Ctrl-W (delete word)
  • Alt-F (jump one word forward)
  • Alt-B (jump one word back)

These get me most of the way around.

It also depends on your terminal emulator. For instance on my Mac I've mapped the above to the typical keybinds (alt-left, alt-right, ctrl-backspace)

path: 0 98083 98498 113959, hotness: undefined, score: 1, children: 1
deepdive 1 point 3 years ago

Thank you :) My question was maybe a bit confusing (not native :( ) and yes I know those EMACs shortcuts to navigate around :). It was relate to how to navigate a multiline in a copy/pasted command in the shell. The solution is (even if it wasn't what I expected) to Ctrl-x Ctrl-e, this opens an editor with my copied command. This is one more step, but it's elgant and takes away the fritction from opening nano myself !

Thank you for your contribution !

path: 0 98083 98498 113959 130834, hotness: undefined, score: 1, children: 0
3nt3r 2 points 3 years ago

Personally if its just a bash command then I dont bother with formatting and just do one-liners. If I want it to look pretty then I’ll put it in a script. If I need to edit something you can use shortcuts like these to jump around the command line to edit whatever you need

path: 0 95011, hotness: undefined, score: 2, children: 1
deepdive 1 point 3 years ago

Hey, thank you for your response :)

It's not about looking pretty, I like to navigate freely like CTRL-E, CTRL-A, ALT-B, ALT-F... speeds up the process and is frictionless (like your link suggests it :P). Sometimes I copy/past an already written command in the CLI with multilines and not being able to navigate thourgh them is frustrating !

path: 0 95011 96069, hotness: undefined, score: 1, children: 0
PopOfAfrica 1 point 3 years ago
path: 0 130931, hotness: undefined, score: 1, children: 2
deepdive 2 points 3 years ago

Thank you for your insight ! :)) I'm relatively new to linux (ubuntu/debian) and this will probably commin handy in the future :). As I read on the web it's going to replace the X Window System. Something new to read through and learn !

path: 0 130931 131310, hotness: undefined, score: 2, children: 1
PopOfAfrica 2 points 3 years ago
path: 0 130931 131310 131368, hotness: undefined, score: 2, children: 0
linux
linux

@lemmy.ml

login for more options
68076
9448
5174

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

  • Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
  • No misinformation
  • No NSFW content
  • No hate speech, bigotry, etc

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

go to feed...