How to paste a code to terminal and execute it line by line? (it has sudo)

When I paste to terminal the following code:

wclean; sudo bash; wmake; 

It asks for password for sudo bash, then I have to type it (no problem). But it doesn't keep going. It stops before wmake.

How to paste entire code to terminal and execute it line by line? I want a simple solution because these codes I paste are from internet, books, tutorials, ...

Replay

Pasting multiple commands at once may lead to problems if one of them waits for terminal input. In this case the rest of the paste will be taken as input for that command and not as separate command to be run afterwards. The most common example is probably the sudo password prompt.

However, Bash is capable of opening a text editor to enter commands, by default it is nano. You start the command editor by pressing Ctrl+X followed by Ctrl+E. The editor launches and everything you typed into the current command line so far will also appear there and can be edited. If the command line was empty though, the editor will be empty as well.

In the editor you can now easily paste or type multiple commands, simply put one command per line and Bash will take care of joining them with semicolons itself.

If you're done and want to submit your list of commands, simply exit the editor (Ctrl+X for nano) and Bash will start to execute all the commands one after the other.

If you enter as super user, all the command you run will be granted with super user privileges, so no password will be asked.

Just type sudo su on the terminal prompt before pasting your commands. The prompt must have been changed from $ to #.

Simple, copy that and paste in a file, and then execute the file, For Example:

nano test.sh
Ctrl+Shift+V [to paste the code]
Ctrl+O [Save it]
Ctrl+X [Exit]
chmod 755 test.sh
./test.sh

Cheers

As @jiipeezz commented, there's nothing wrong with not continue after sudo bash, because with this command you open a new shell. In fact, terminating the shell ( with exit ) the the next command is executed. If you want to run the command wmake as superuser, then you have to pass the command as argument to shell, with sudo bash -c 'wmake'. Try:

wclean;
sudo bash -c 'wmake';

But I do not think it makes sense to run a single command on a new shell, instead it uses sudo to run the command directly.

In your case, the answer is to change the commands you're using. You are trying to start a bash shell as root in order to run a command. The clean way of doing this is to just run sudo command. So, all you need is to copy paste the following directly into your terminal:

wclean
sudo wmake

You don't need to first run sudo bash and then wmake, run wmake with sudo directly. You also don't need the ; at the end of each command. The ; is only needed if you are running two commands on the same line (e.g. comm1; comm2).

You could change the semicolons(;) with '&&' without the quotes, in your case for example:

wclean &&
sudo bash &&
wmake

BTW no '&&' at the end.

Have a nice day

Category: command line Time: 2016-07-29 Views: 4
Tags: command line

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.273 (s). 12 q(s)