malti
Posts: 9
Joined: Sun Oct 30, 2016 9:23 am

sudo !

Sun Oct 30, 2016 9:38 am

I read of super user sudo mode to edit and install apps etc

I understand that instructions are written on a text editor, but how do you execute or run a text file ?
Do you just copy and paste, and paste to where?

jbudd
Posts: 1446
Joined: Mon Dec 16, 2013 10:23 am

Re: sudo !

Sun Oct 30, 2016 12:41 pm

Here is a simple program which you could put in a file.

Code: Select all

#! /bin/bash
echo "Hello World"
The first line effectively tells the Pi what language it is in - in this case Bash shell script.
It doesn't matter what the name of the file is, you can call it "hello", "hello.txt", "hello.sh" or anything.

You have to make the file executable.

Code: Select all

chmod +x hello.sh
and then you execute it by typing it's name - provided that the command line interpreter knows where to find it. So

Code: Select all

./hello.sh
should work. ("./" means look in the current directory)

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: sudo !

Sun Oct 30, 2016 12:45 pm

You only need sudo when you need to elevate privileges, which is almost never for any program you're going to write.

sudo gives you the simple way to destroy your machine because it bypasses all security controls that are there to stop you holding a smoking weapon and wondering why your foot now has a large hole in it.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

malti
Posts: 9
Joined: Sun Oct 30, 2016 9:23 am

Re: sudo !

Sun Oct 30, 2016 3:20 pm

thanks

what does this means?

-bash
~$

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: sudo !

Sun Oct 30, 2016 3:56 pm

The $ prompt means you have a shell running with a non-privileged user.
The ~ means your current working directory is your home directory (usually /home/pi for the pi user).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

malti
Posts: 9
Joined: Sun Oct 30, 2016 9:23 am

Re: sudo !

Mon Oct 31, 2016 7:13 am

excuse my ignorance
this is my impression

In windows, we write instructions etc on an editor and paste it to c: windows/ 32 etc etc or a ready assembled exe file

In Raspbian , indeed in Linux, I am to understand that we write the instructions on an editor like nano and paste it to WHERE in the system ?

Authors give you the instructiobs, but they assume that you know where to paste them!

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: sudo !

Mon Oct 31, 2016 7:38 am

Linux , just like Windows , has a PATH variable.
Unlike Windows the current directory is NOT part of the
PATH by default (that is a security feature).

Code: Select all

echo $PATH
shows which folders are searched for
commands/scripts/executables by default.

https://en.m.wikipedia.org/wiki/PATH_(variable)


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
RaTTuS
Posts: 10563
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: sudo !

Mon Oct 31, 2016 7:57 am

in respect to the actual title
sudo !!
will run the last command as sudo
so if you type a long command and you forget the sudo then you don't have to up arrow , beginning of line, sudo enter , or retype it all you just need to
sudo !!
see
https://www.gnu.org/software/bash/manua ... nteraction
for extra info
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

jbudd
Posts: 1446
Joined: Mon Dec 16, 2013 10:23 am

Re: sudo !

Mon Oct 31, 2016 8:20 am

In windows, we write instructions etc on an editor and paste it to c: windows/ 32 etc etc or a ready assembled exe file

In Raspbian , indeed in Linux, I am to understand that we write the instructions on an editor like nano and paste it to WHERE in the system ?
In a terminal window, where it displays you the dollar prompt - which looks something like "pi@raspberrypi:~ $ ", you type something, lets say you type "date".
The command interpreter, which is also known as the bash shell, tries to work out what to do with it.It looks in all of the directories specified in the PATH setting. If it finds an executable file, which in this case it will, /bin/date, then it executes the file and shows you the output. Then it gives you another dollar prompt. If it can't find an executable file it displays "Command not found".
You can put your own commands into a file of any name, make it executable and run it by telling bash where to find it.

When you are using the terminal window you are in your home directory /home/pi (you can change directory with the cd command). If you create a file with the nano editor, or by other means, it will be created in the directory you are currently in.
"nano myfirstprogram.sh" will run the editor program to create a file called myfirstprogram.sh

You can of course create files, make them executable and run them from within X Windows, but the same thing is going on in the background.

Return to “Beginners”