Link Search Menu Expand Document

Shell Script Introduction

Table of contents

Shell script usage

  • Allow to run multiple commands together
  • Allow if-else statements and loops
  • Choose a file, create 1540 copies of it with different names and put those to different folders

Sequence of commands

  • Ask file to copy
  • Save file name in a variable
  • Ask number of copies and locations to copy to
  • Save those in other variables
  • Create the desire folders
  • Create a loop that copy the file, desired number of times in the desired locations

Edit and read script

Read more on Basic Bash

Change $PATH for a script

  • Add the script files to the $PATH
echo ${variable-name}
  • Add below into ~/.bashrc in droplet to define path to the script
# define my custom scripts
export PATH="/root/scripts:$PATH"
  • Create file, add below content
#! /bin/bash
echo "what is your name"
read your-name
#2nd read option: 
#remove first 2 lines then: read -p "what is your name " your-name

echo "hello $yourname nice to meet you!"
echo -----------------------*
  • Give the file an executable permission
chmod +x
  • Once added, in terminal enter:, it just works in any directories.