How it works by Gugi -- Bash Scripts Examples ~~LINUX~~

Forum rules
Before you post please read how to get help
Post Reply
Gugi
Level 1
Level 1
Posts: 16
Joined: Sat Sep 29, 2018 11:45 am
Location: Somewhere in Poland
Contact:

How it works by Gugi -- Bash Scripts Examples ~~LINUX~~

Post by Gugi » Sun Oct 21, 2018 2:17 am

Hello everyone, today i decide to write this tutorial with name 'HOW IT WORKS'

You need to know :

*Every single script start with:

Code: Select all

#! /bin/bash
*Permission for new script:

Code: Select all

chmod 641 NAMEOFSCRIPT
Where is my Script:

Code: Select all

which NAMEOFSCRIPT
My Directory:

Code: Select all

#! /bin/bash
vdir /home/GUGI
Text to see in terminal :

Code: Select all

#! /bin/bash
zmienna="HERE IS YOUR TEXT :)"
echo $zmienna
$PATH folders checker:

Code: Select all

#! /bin/bash
echo $PATH
Lock File for Automated Scripts:

Code: Select all

while [-f $lockfile ] ; do
sleep 1
done
touch $lockfile
Mac Adress changer (you need macchanger & offline mode):

Code: Select all

#!/bin/bash
ifconfig INTERFACE down

macchanger -r INTERFACE

sleep 5

ifconfig INTERFACE up

service network-manager restart

echo $'\n'
echo MAC Is Changed, Enjoy! ALL SAFE _/
MORE SOON
Last edited by Gugi on Wed Nov 14, 2018 2:10 pm, edited 16 times in total.
Image

REGARDS,
Gugi

User avatar
smurphos
Level 8
Level 8
Posts: 2255
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher...

Re: HOW IT WORKS by GUGI -- Bash Scripts Examples ETC

Post by smurphos » Sun Oct 21, 2018 2:47 am

~/bin or ~/.local/bin are better locations for user added scripts - both are added to the users $PATH if the folders exist so you can run them from anywhere with just the script name.

I also wouldn't recommend giving global edit and execute permissions. Do you really want other users to be able to edit your scripts and execute them? Probably a bad idea.. :roll: :wink: personally I'd go for chmod 744 <script_name> as your default permissions in your script folder.

Most bash script authors I've seen capitalise variables for easier reading.
Last edited by smurphos on Sun Oct 21, 2018 2:57 am, edited 1 time in total.

Gugi
Level 1
Level 1
Posts: 16
Joined: Sat Sep 29, 2018 11:45 am
Location: Somewhere in Poland
Contact:

Re: HOW IT WORKS by GUGI -- Bash Scripts Examples ETC

Post by Gugi » Sun Oct 21, 2018 2:55 am

smurphos wrote:
Sun Oct 21, 2018 2:47 am
~/bin or ~/.local/bin are better locations for user added scripts - both are added to the users $PATH if the folders exist so you can run them from anywhere with just the script name.

Most bash script authors I've seen capitalise variables for easier reading.
Thanks for that, gonna see but at first steps just create new folder in my desktop and run it from ..

This scripts atm not starting with Linux starttup so dont worry ;) Yeah, i will think on it ;D

All comes with time :D
Last edited by Gugi on Sun Oct 21, 2018 2:58 am, edited 1 time in total.
Image

REGARDS,
Gugi

User avatar
smurphos
Level 8
Level 8
Posts: 2255
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher...

Re: HOW IT WORKS by GUGI -- Bash Scripts Examples ETC

Post by smurphos » Sun Oct 21, 2018 2:58 am

I edited my reply with regards to your permission recommendation BTW.

gm10
Level 13
Level 13
Posts: 4689
Joined: Thu Jun 21, 2018 5:11 pm

Re: HOW IT WORKS by GUGI -- Bash Scripts Examples ETC

Post by gm10 » Sun Oct 21, 2018 2:59 am

Gugi wrote:
Sun Oct 21, 2018 2:17 am
Every single script need to have

Code: Select all

#!/bin/bash
Bash is a rather heavy-weight shell, you should never declare that explicitly unless your script needs bash-specific functions.

Otherwise it's best practice to either use the system's default shell:

Code: Select all

#!/bin/sh
or explicitly declare a light-weight shell:

Code: Select all

#!/bin/dash
On all Mint editions those two above are the same thing since Dash is the system default.
Gugi wrote:
Sun Oct 21, 2018 2:17 am
You need to give permissions for script[/b]
My recommendation is : chmod 777 NAMEOFSCRIPT
That's a dangerous recommendation. I advise nobody do that unless they actually understand what they're doing. Use:

Code: Select all

chmod u+x /your/script
As a side note, you should lose the all caps from your title and the big and colourful letters from your post...
Last edited by gm10 on Sun Oct 21, 2018 3:02 am, edited 1 time in total.

Gugi
Level 1
Level 1
Posts: 16
Joined: Sat Sep 29, 2018 11:45 am
Location: Somewhere in Poland
Contact:

Re: HOW IT WORKS by GUGI -- Bash Scripts Examples ETC

Post by Gugi » Sun Oct 21, 2018 3:01 am

smurphos wrote:
Sun Oct 21, 2018 2:58 am
I edited my reply with regards to your permission recommendation BTW.
With this recommendation i means that ONLY YOU IS OWNER OF PC ;D

Im only one user of my laptop so ;D

BTW when my script is done, my permissions is
chmod 511 :) read only
because if its done, you dont need to edit ;D
Image

REGARDS,
Gugi

Gugi
Level 1
Level 1
Posts: 16
Joined: Sat Sep 29, 2018 11:45 am
Location: Somewhere in Poland
Contact:

Re: How it works by Gugi -- Bash Scripts Examples ~~LINUX~~

Post by Gugi » Tue Nov 13, 2018 8:54 am

UPDATE

LOCKFILE SCRIPT
Image

REGARDS,
Gugi

User avatar
Moem
Level 17
Level 17
Posts: 7243
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: HOW IT WORKS by GUGI -- Bash Scripts Examples ETC

Post by Moem » Tue Nov 13, 2018 8:56 am

gm10 wrote:
Sun Oct 21, 2018 2:59 am
As a side note, you should lose the all caps from your title and the big and colourful letters from your post...
I agree. It's distracting and makes things harder to read, not easier.
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!

Gugi
Level 1
Level 1
Posts: 16
Joined: Sat Sep 29, 2018 11:45 am
Location: Somewhere in Poland
Contact:

Re: HOW IT WORKS by GUGI -- Bash Scripts Examples ETC

Post by Gugi » Tue Nov 13, 2018 10:32 am

Moem wrote:
Tue Nov 13, 2018 8:56 am
gm10 wrote:
Sun Oct 21, 2018 2:59 am
As a side note, you should lose the all caps from your title and the big and colourful letters from your post...
I agree. It's distracting and makes things harder to read, not easier.
done
Image

REGARDS,
Gugi

Post Reply

Return to “Scripts & Bash”