5

Maybe it's not that important, but I think it's worth a quick mention here on meta. Multi-line shell commands are annoying to deal with. Here's a blatant example:

find . -type f | \
while read -r filepath; \
do echo "$filepath"; \
done

This is a nice way to present a command, but at the same time it goes to the detriment of the command's usability. For example, try, when using it, to change something other than the last line without ending up copy-pasting each single line.

I think it would be nice if such commands would be posted along with an editable one-line version of them, for the ease of copy-paste-edit-run them directly.

| |
  • 2
    Good idea! I'll use that from now on!!! Now you go edit all the answers on the site that contain such commands and add one-liners! ;-) – Fabby Jul 6 '15 at 20:50
  • @Fabby I'd rather not (~1569 posts!), but in case someone is willing to edit their own posts I'll provide a very rough query to find the offending ones ;) You have only one by the way! Congratulations! – kos Jul 6 '15 at 22:03
  • 1
    None now! :P ;-) – Fabby Jul 6 '15 at 22:12
13

I propose that we leave them as-is, and teach the users to avoid the insanity of editing complex commands directly in the shell. Bash, for one, allows us to edit the current command in an editor by pressing CtrlxCtrle (via the readline library).

| |
  • 3
    Nice, I didn't know about this. Seconded – kos Jul 7 '15 at 13:32
0

There is also ESCV on some ksh (I think about HP-UX).

  • you must be in vi mode (set -o vi).

(edit in post because of format)

terminal is gnome-terminal, LTS 14.04.2

#stty -a
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

what i did: enter a two line command

ls |
wc -l

run the command,

  • then ESCk, this recall the command in one line, with a ^J
  • then ESCv, this call

    • vi, with command on two lines (HP-UX),
    • nano with command on one line (Ubuntu).
| |
  • Thanks for the suggestion, but I'm testing this in ksh and it's not working (at least in gnome-terminal). I think it's a feature of your terminal – kos Jul 20 '15 at 7:09
  • Nope, it's still not working. Which terminal are you on? – kos Jul 20 '15 at 7:24
  • Looks like a putty feature, which I can't test; Ctrl+K and Ctrl+K brings the second most recent command run (in gnome-terminal with ksh and vi set). Can you test this in gnome-terminal (or any other "local" terminal)? – kos Jul 20 '15 at 7:41
  • I confirm the Ubuntu/nano/set -o vi version 14.04.2 – Archemar Jul 20 '15 at 7:52
  • Then apologize, it must be due to my current (Debian) environment. Gonna test this as soon as I get on an Ubuntu machine. – kos Jul 20 '15 at 7:54
  • vi mode, not vi more. – Erkin Alp Güney Jul 21 '15 at 11:00
  • vi mode, not vi more. – Erkin Alp Güney Jul 21 '15 at 11:01
  • @ErkinAlpGüney thank you, vi mode is more of vi ! – Archemar Jul 21 '15 at 11:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .