Paste multiple commands in sudo?

hello everyone,

I have a problem, I am trying to paste multiple command lines with sudo but only the first one is successful. on the other hand, when executing without sudo these if they are exdosos. how can I solve it?
I leave a couple of examples

[user@server ~]# ls test
[user@server ~]# sudo cp test1 test
sudo cp test2 test
sudo cp test3 test
sudo cp test4 test
[user@server ~]# ls test
test1
[user@server ~]# rm -rf test/test1
[user@server ~]# ls test
[user@server ~]# cp test1 test
[user@server ~]# cp test2 test
[user@server ~]# cp test3 test
[user@server ~]# cp test4 test
[user@server ~]# ls test
test1 test2 test3 test4
[user@server ~]#

If it were that simple enumeration, then
sudo cp test{1..4} test
would copy four files with one command.

But I presume the real case has no such easy pattern?

Exactly, it’s just an example. The real case is files with different names and directories that I can only access with sudo. I also did shell script tests which were also unsuccessful.

What if you had:

$ cat sample
sudo cp test1 test
sudo cp test2 test
sudo cp test3 test
sudo cp test4 test

and you do:

$ source sample

(Or was that already unsuccessful?)

It is working as expected if sudo is not asking for the password, so it seems that sudo is resetting the paste buffer after the password was entered.

→ authenticate before pasting your commands

e.g. use a dummy command

$ sudo true
enter password
$ sudo $yourcommands

well, that were my experiments. strange that nowhere above I find password prompt mentioned

Dear,
Thank you very much for your answer, both were very helpful, it did not solve my problem but it did help me to give 2 different options to the user.

The problem may be in the user permissions, since other users who are in an IPA network can paste the command lines without presenting problems.

Did you try separating commands with &&? I haven’t tried it with sudo, but it works otherwise.
sudo uname -r && grub2-editenv list

Your && is logically:

IF 'uname -r' run as root succeeds
THEN run 'grub2-editenv list'

That differs from:

sudo uname -r
grub2-editenv list

only by the second command being conditional.