Skip to content

Commit

Permalink
Merge pull request #10 from DeNepo/02-variables-and-shell-expansions
Browse files Browse the repository at this point in the history
add 02-variables-and-shell-expansions
  • Loading branch information
sammou00 authored Aug 7, 2024
2 parents 538d627 + 539552d commit aee93d6
Show file tree
Hide file tree
Showing 168 changed files with 3,006 additions and 599 deletions.
7 changes: 4 additions & 3 deletions 00-build-bash-script/0-examples/00.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# Author: Samir M.
# Date: 2024-03-12
# Modified: 2024-03-12
# Version : 1.0
# Description: The main components of a shell script
# Usage: ./00.sh

Expand All @@ -16,9 +16,10 @@

# 3. Exit status will be at the end of the script

exit 0
#-------------------------------------------------------------#

exit 0

# How to run the script:
# 1. Open the terminal
# 2. `chmod 744 <path-to-the-script>`
Expand Down
12 changes: 3 additions & 9 deletions 00-build-bash-script/0-examples/01.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# Author: Samir M.
# Date: 2024-03-12
# Modified: 2024-03-12
# Version : 1.0
# Description: echo command
# Usage: ./01.sh

Expand All @@ -18,16 +18,10 @@ echo -e "Hello,\tWorld! third example"

# What is the difference between the three echo commands above?

exit 0

#-------------------------------------------------------------#
exit 0

# How to run the script:
# 1. Open the terminal
# 2. `chmod 744 <path-to-the-script>`
# 3. `./<path-to-the-script>`





4 changes: 2 additions & 2 deletions 00-build-bash-script/0-examples/02.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Introduction

The `$SHELL` variable in Unix-like operating systems is an environment variable that holds the path to the user's preferred shell.
The `$SHELL` variable in Unix-based and Unix-like operating systems is an environment variable that holds the path to the user's default shell.

## Usage

Expand Down Expand Up @@ -38,5 +38,5 @@ This command sets the default shell to Zsh, for example.
When working with the `$SHELL` variable:

- Ensure compatibility by using the appropriate syntax for the current shell.
- Use the `$SHELL` variable dynamically in scripts to adapt to users' preferences.
- Use the `$SHELL` variable dynamically in scripts to adapt to user's preferences.
- Be cautious when changing the default shell, considering compatibility with existing scripts and configurations.
11 changes: 5 additions & 6 deletions 00-build-bash-script/0-examples/02.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# Author: Samir M.
# Date: 2024-03-12
# Modified: 2024-03-12
# Version: 1.0
# Description: The $SHELL varibale
# Usage: ./02.sh

#-------------------------------------------------------------#

# $SHELL is a shell variable that contains the path to the current shell
# $SHELL is a shell variable that contains the path to the default shell

echo "$SHELL"

Expand All @@ -19,11 +19,10 @@ echo "Your default shell is {$SHELL}"
# Can I change the default shell? How?
# Are there any other shell variables?

exit 0

#-------------------------------------------------------------#
exit 0

# How to run the script:
# 1. Open the terminal
# 2. `chmod 744 <path-to-the-script>`
# 3. `./<path-to-the-script>`
# 3. `./<path-to-the-script>`
11 changes: 4 additions & 7 deletions 00-build-bash-script/0-examples/03.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# Author: Samir M.
# Date: 2024-03-02
# Modified: 2024-03-02
# Version: 1.0
# Description: Comments in bash script.
# Usage: ./02.sh

Expand All @@ -12,21 +12,18 @@

# Single line comment.


# Multi-line comment.
# Multi-line comment.
# Multi-line comment.

echo "Comments in bash script." # Inline comment.

# Why the shebang is not a comment?

exit 0
# is the shebang a comment?

#-------------------------------------------------------------#
exit 0

# How to run the script:
# 1. Open the terminal
# 2. `chmod 744 <path-to-the-script>`
# 3. `./<path-to-the-script>`

16 changes: 8 additions & 8 deletions 00-build-bash-script/0-examples/04.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

# Author: Samir M.
# Date: 2024-03-02
# Modified: 2024-03-02
# Version: 1.0
# Description: Make your script more professional.
# Usage: ./04.sh

#-------------------------------------------------------------#

# To make your script more professional, you can use 5 pecies of information

# 1. Author : the name of the person who created the script
# 2. Date of creation : the date when the script was created
# 3. Modified date : the date when the script was last modified
# 4. Description : what the script does
# 5. Usage : how to use the script
# 1. Author : the name of the person who created the script
# 2. Date : the date when the script was created
# 3. Version : the version of the script
# 4. Description : a brief description of the script
# 5. Usage : how to use the script

#-------------------------------------------------------------#
exit 0

#-------------------------------------------------------------#
# How to run the script:
# 1. Open the terminal
# 2. `chmod 744 <path-to-the-script>`
# 3. `./<path-to-the-script>`
# 3. `./<path-to-the-script>`
14 changes: 6 additions & 8 deletions 00-build-bash-script/0-examples/05.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# Author: Samir M.
# Date: 2024-03-12
# Modified: 2024-03-12
# Version: 1.0
# Description: Add and remove scripts to/from the PATH
# Usage: ./05.sh

#-------------------------------------------------------------#


# To see the PATH variable, you can use the following command
echo "{$PATH}"

# Add scripts to the PATH allows you to run the script from any directory without specifying the full path

## To add 0-examples to the PATH, you can use the following command (replace the path with your own)
export PATH=$PATH:$HOME/Desktop/work/master-classes/bash-scripting/00-build-bash-script/0-examples
export PATH=$PATH:$HOME/Desktop/denepo/bash-scripting/00-build-bash-script/0-examples

echo "{$PATH}"

## To remove 0-examples from the PATH, you can use the following command (replace the path with your own)
export PATH=${PATH%:"$HOME"/Desktop/work/master-classes/bash-scripting/00-build-bash-script/0-examples}
export PATH=${PATH%:"$HOME"/Desktop/denepo/bash-scripting/00-build-bash-script/0-examples}

echo "{$PATH}"

exit 0

#-------------------------------------------------------------#
exit 0

# How to run the script:
# 1. Open the terminal
# 2. `chmod 744 <path-to-the-script>`
# 3. `./<path-to-the-script>`
# 3. `./<path-to-the-script>`
9 changes: 4 additions & 5 deletions 00-build-bash-script/0-examples/06.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# Author: Samir M.
# Date: 2024-03-12
# Modified: 2024-03-12
# Version: 1.0
# Description: Set up secure script permissions
# Usage: ./06.sh

Expand All @@ -29,11 +29,10 @@ ls -l 06.sh
# chmod 744 <file-name>.sh
# 744 means that the owner has read, write and execute permission, and the group and public have only read permission

exit 0

#-------------------------------------------------------------#
exit 0

# How to run the script:
# 1. Open the terminal
# 2. `chmod 744 <path-to-the-script>`
# 3. `./<path-to-the-script>`
# 3. `./<path-to-the-script>`
12 changes: 3 additions & 9 deletions 00-build-bash-script/1-blanks/00.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# Author: Samir M.
# Date: 2024-03-12
# Modified: 2024-03-12
# Version: 1.0
# Description: The main components of a shell script
# Usage: _/__.sh

Expand All @@ -21,11 +21,5 @@
# The exit status is a ________ value that a script returns upon completion.
# Typically, ___ indicates success and non _____ indicates failure.

exit 0
#-------------------------------------------------------------#

# How to run the script:
# 1. Open the ________
# 2. `chmod ___ <path-to-the-script>`
# 3. `./<path-to-the-script>`

exit 0
19 changes: 4 additions & 15 deletions 00-build-bash-script/1-blanks/01.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# _______: Samir M.
# Date: 2024-03-12
# Modified: 2024-03-12
# Version: 1.0
# Description: echo command
# ______: ./01.sh

#-------------------------------------------------------------#

echo "__________ first example" # Hello, World! first example

echo -e "__________ second example"
echo -e "__________ second example"
# Hello,
# World! second example

echo -e "__________ third example" # Hello, World! third example

# What is the difference between the three echo commands above?

exit 0
#-------------------------------------------------------------#

# How to run the script:
# 1. Open the ________
# 2. `chmod ___ <path-to-the-script>`
# 3. `./<path-to-the-script>`






exit 0
12 changes: 3 additions & 9 deletions 00-build-bash-script/1-blanks/02.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# Author: __________
# Date: __________
# Modified: __________
# Version: __________
# Description: The $SHELL variable
# Usage: ./___.sh

Expand All @@ -19,11 +19,5 @@ echo "Your default shell is {________}"
# Can I change the default shell? How?
# Are there any other shell variables?

exit 0

#-------------------------------------------------------------#

# How to run the script:
# 1. Open the ________
# 2. `chmod ___ <path-to-the-script>`
# 3. `./<path-to-the-script>`
exit 0
17 changes: 5 additions & 12 deletions 00-build-bash-script/1-blanks/03.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# Author: __________
# Date: __________
# Modified: __________
# Version: __________
# Description: Comments in bash script.
# Usage: ./___.sh

Expand All @@ -21,15 +21,8 @@
echo "Comments in bash script." # Inline comment.
# Inline comments start with the ________ symbol and extend to the end of the line.

# Why the shebang is not a comment?
# The shebang is not a comment because it is ________ by the shell to determine the ________ to be used for executing the script.
# Is shebang a comment?
# The shebang is a special comment because it is ________ by the shell to determine the ________ to be used for executing the script.

exit 0
#-------------------------------------------------------------#

# How to run the script:
# 1. Open the ________
# 2. `chmod ___ <path-to-the-script>`
# 3. `./<path-to-the-script>`


exit 0
14 changes: 5 additions & 9 deletions 00-build-bash-script/1-blanks/04.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/opt/homebrew/bin/bash

# Author: __________
# Date: __________
# Modified: __________
# Version: __________
# Description: Make your script more professional.
# Usage: ./___.sh

Expand All @@ -12,13 +12,9 @@

# 1. __________ : the name of the person who created the script
# 2. __________ : the date when the script was created
# 3. __________ : the date when the script was last modified
# 3. __________ : the version of the script
# 4. __________ : what the script does
# 5. __________ : how to use the script
# 5. __________ : how to use the script

exit 0
#-------------------------------------------------------------#
# How to run the script:
# 1. Open the ________
# 2. `chmod ___ <path-to-the-script>`
# 3. `./<path-to-the-script>`
exit 0
Loading

0 comments on commit aee93d6

Please sign in to comment.