Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bash Shell Scripts Utility Hub 🛠️

A collection of lightweight, efficient Bash shell scripts for performing mathematical computations, string checks, file operations, and CLI utility tasks.

These scripts have been modernized, debugged, and optimized to run seamlessly across both macOS (using default Bash 3.2) and Linux (Bash 4.0+) environments.


📂 Directory Structure & Program Descriptions

Here is a breakdown of every utility script included in this repository:

1. Prime Numbers Generator (100prime)

  • Description: Generates and displays all prime numbers between 1 and 100.
  • Usage:
    ./100prime

2. Triangle Area Calculator (Areatri)

  • Description: Prompts the user to enter the base and height of a triangle and calculates its area. Uses the bc utility for floating-point calculations.
  • Usage:
    ./Areatri
    # Sample prompt:
    # enter base of triangle: 5
    # enter height of triangle: 4.5
    # Output: 11.25

3. Armstrong Number Checker (Armstrongno)

  • Description: Checks whether a user-input number is an Armstrong number (a number that is equal to the sum of its own digits each raised to the power of the number of digits, e.g., $1^3 + 5^3 + 3^3 = 153$).
  • Usage:
    ./Armstrongno
    # Sample input: 153
    # Output: 153 is an Armstrong number.

4. Interactive Calculator Menu (Calc)

  • Description: A terminal-based interactive calculator with a menu options layout:
    • a: Addition
    • s: Subtraction
    • m: Multiplication
    • d: Division (includes zero-division check)
    • q: Quit
  • Usage:
    ./Calc

5. Safe File Editor (Editfile)

  • Description: Opens a specified file in vim only after performing double validation checks: ensuring that the file exists and that the user has write permissions.
  • Usage:
    ./Editfile <filename>

6. Fibonacci Sequence Generator (Fibonacci)

  • Description: Generates and prints the Fibonacci series up to a user-specified number of terms ($N$).
  • Usage:
    ./Fibonacci
    # Sample Input: 5
    # Output: 0 1 1 2 3

7. Natural Numbers Summation (Natsum)

  • Description: Lists the first 20 natural numbers (1 to 20) and calculates their total sum ($210$).
  • Usage:
    ./Natsum

8. Palindrome Checker (Palindrome)

  • Description: Case-insensitively checks if a user-provided word reads the same backward as forward.
  • Usage:
    ./Palindrome
    # Sample Input: Racecar
    # Output: racecar is a palindrome.

9. Perfect Numbers Generator (Perfectno)

  • Description: Searches and prints all perfect numbers (a positive integer that is equal to the sum of its proper divisors, e.g., $6 = 1 + 2 + 3$) between 1 and 500.
  • Usage:
    ./Perfectno
    # Output: 6, 28, 496

10. File Resolver (Searchfile)

  • Description: Checks whether a file exists locally. If it exists, it outputs the absolute, fully-resolved system path using the realpath command.
  • Usage:
    ./Searchfile <filename>

11. Digit Counter (no_of_digits)

  • Description: Calculates the total number of digits in any integer. It supports positive numbers, negative numbers, and zero.
  • Usage:
    ./no_of_digits
    # Sample Input: -9876
    # Output: Number of digits: 4

🚀 How to Set Up and Run

  1. Clone the repository:

    git clone https://github.com/HypnoticShield/Shellscripts.git
    cd Shellscripts
  2. Make the scripts executable: By default, the scripts might not have execution permissions. Grant them using:

    chmod +x *
  3. Run a script:

    ./Calc

🛠️ Modernization & Fixes Applied

To ensure these utilities run properly out-of-the-box, several bug fixes were applied:

  • Armstrongno: Fixed a bug where checking $sum -eq $number threw an error because $number was undefined. It now correctly checks $n.
  • Calc: Fixed division validation which was checking if input was less than 0 rather than equal to 0. Removed a syntax-breaking continue outside of a loop, replacing it with a clean exit 1 block.
  • Editfile: Corrected flipped file check logic. Originally checked for writable status (-w) before confirming the file exists (-e), printing "File doesn't exist" even when a file existed but lacked write permission.
  • no_of_digits: Fixed loop evaluation where an uninitialized variable $number caused the script to always print 0 digits. It now handles inputs (including negative numbers and zero) correctly.
  • Palindrome: Modernized case-lowercasing. Replaced ${w,,} (which fails in Bash versions older than 4.0, such as macOS default shell) with tr '[:upper:]' '[:lower:]' to ensure cross-platform compatibility.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages