1

When I paste multiple commands into putty window,
commands stop executing after first sudo.

Why?

My clipboard (I'm careful to copy also newline after the 2nd command)

sudo -u smith echo aaaaaaaa ;

echo bbbbbbbb ;

Result:

$ sudo -u smith echo aaaaaaaa ;

echo bbbbbbbb ;

aaaaaaaa
$

It executes echo aaaaaaaa as expected, but 2nd command is not executed.

Setup: I connect from windows 10 via putty to red hat server, shell is bash.


debugging attempt

Seems sudo hijacks pasted input somehow. (-n option does not help)

# Given clipboard:
sleep 5s
echo bbbbbb

# Result is:
$ sleep 5s
$ echo bbbbbb # <-- this line gets onto screen AFTER sleep has finished
bbbbbb

But if sleeping is done with sudo

Given clipboard:
sudo -u smith sleep 5s
echo bbbbbb

# Result is:
$ sudo -u smith sleep 5s
echo bbbbbb # <-- this line gets onto screen BEFORE sleep has finished
1
  • 1
    Use an additional `\` (backslash) at end of each of your lines, but the last line.
    – paladin
    Commented Apr 13, 2022 at 11:12

1 Answer 1

1

Short answer, use a backslash at end of each line, but the last line.

sudo -u smith sleep 5s;\
echo bbbbbb

This will work.

2
  • Thanks. This works. Any chance you have explanation on "why this happens"? Your solution puts makes it identical to putting both commands on the same line sudo -u smith sleep 5s; echo bbbbbb, but why does this new line matters for sudo at all? Commented Apr 13, 2022 at 11:19
  • It's a built-in "comfort" function of sudo, otherwise you would have to enter 2 times your sudo password for a command like sudo apt update && sudo apt upgrade. I guess it's possible to disable this, but I don't recommend to do so.
    – paladin
    Commented Apr 13, 2022 at 11:25

You must log in to answer this question.

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