/shell_scripting

Shell scripting with ZSH and BASH

Primary LanguageShell

https://www.youtube.com/watch?v=tK9Oc6AEnR4&ab_channel=freeCodeCamp.org

Create Text File

  1. Create file vim textfile.txt

    a. Type i to enter Insert mode
    b. Enter Hello World!
    c. Hit esc, then enter :qw to write and quit
    d. Output file cat textfile.txt

Hello World

  1. Create file vim shellscript.sh

    a. Type a to enter Append mode, which outputs character after cursor
    b. Enter echo Hello World!
    c. Hit esc, then enter :qw to write and quit
    d. Run script zsh [shelltest.sh](http://shelltest.sh) or bash shelltest.sh

Run Script without ZSH or BASH Command

  1. Modify file vim shellscript.sh

    #!/bin/zsh
    echo Hello World!

    a. modify permissions chmod u+x shellscript.sh b. Run script ./shellscript.sh

Variables

#!/bin/zsh

## BAD
cp /my/location/from /my/location/to
cp /my/location/from/here /my/location/to/there

## GOOD

MY_LOCATION_FROM=/my/location/from
MY_LOCATION_TO=/my/location/to

cp $MY_LOCATION_FROM $MY_LOCATION_TO
cp "$MY_LOCATION_FROM" "$MY_LOCATION_TO"
  1. Create file vim hellothere.sh

    #!/bin/zsh
    FIRST_NAME=Abraham
    LAST_NAME=Choi
    
    echo Hello $FIRST_NAME $LAST_NAME

    a. modify permissions chmod u+x hellothere.sh b. Run script ./hellothere.sh

Arguments

  1. Create file vim interactive.sh

    #!/bin/zsh
    
    echo "What is your first name?"
    read FIRST_NAME
    echo "What is your last name?"
    read LAST_NAME
    
    echo Hello $FIRST_NAME $LAST_NAME

    a. modify permissions chmod u+x interactive.sh b. Run script ./interactive.sh

  2. Create file vim posargs.sh

    #!/bin/zsh
    
    echo Hello $1 $2

    a. modify permissions chmod u+x posargs.sh b. Run script ./posargs.sh [ARG 1] [ARG 2]