Notes for Computer Information Technology 160
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

oct1.md 1.5KB

October 1

  • #!
  • chmod [augo]+x -f

  • Control Flow

    • If
    • While (until)
    • For ()
    • For () in ()

Files and Commands

$ bash ./f          # run file "f" in a subshell
$ bash -c <command> # run <command> in a subshell
$ ./f               # execute file "f"
$ which <command>   # where is <command> in path on filesystem
$ locate <string>   # find all instances of <string> on filesystem

Find Commands

$ find <location> -type d                    # find a directory
$ find <location> -name <regular expression> # find by name
$ find / -name lab3.txt                      # find file named "lab3.txt" in /

You can search with regular expressions

File Command

$ file <file> # get file type, examples:

$ file ch1.lisp
ch1.lisp: Lisp/Scheme program, ASCII text

$ file ch5.py
ch5.py: Python script, ASCII text executable

Date Command

$ date
Mon Oct  1 13:22:55 PDT 2018

$ date +<format> # date in <format>

$ date +%A
Monday

$ DAY_OF_WEEK = $(date +%A)

$ echo $DAY_OF_WEEK
Monday

If Statement

#!/bin/bash
if [[ boolean ]]; then
  echo "true"
else
  echo "false"
fi #end if

If Statement with Date Command

#!/bin/bash             # ShaBang for Bash Script

DAY_OF_WEEK=$(date +%A) # set var to output of date command eg "Monday"

if [[ "$DAY_OF_WEEK" == "Monday" ]];
then
  echo "It is Monday my dudes."
  echo "Today you have CIT160!"
else
  echo "It is not Monday my dudes."
  echo "Better do your CIT labs!"
fi