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

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Gugi

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

Post by Gugi »

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 LockBot on Wed Dec 28, 2022 7:16 am, edited 17 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

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

Post by smurphos »

~/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.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Gugi

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

Post by Gugi »

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.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

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

Post by smurphos »

I edited my reply with regards to your permission recommendation BTW.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
gm10

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

Post by gm10 »

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 amYou 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

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

Post by Gugi »

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
Gugi

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

Post by Gugi »

UPDATE

LOCKFILE SCRIPT
User avatar
Moem
Level 22
Level 22
Posts: 16226
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 »

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

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

Post by Gugi »

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
Locked

Return to “Scripts & Bash”