Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 1.1 KB

bash-1.md

File metadata and controls

55 lines (44 loc) · 1.1 KB

Bash

# Check if command is in PATH
checkDep() {
     path=`command -v ${1}` && echo "${1} found at ${path}" || { echo "${1} not found" >&2 ; exit 1; }
}
# Get output of command. https://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output/
# i.e. save output of date to var now
now=$(date)
File testing

![](https://i.imgur.com/QGkHbPm.png)
# Pipe output to file.
# i.e. pipe output of ls to output.txt
ls > output.txt
# Check if no arguments passed
if [ $# -eq 0 ] then ... fi
# Check if file does not exist
# Putting ! before makes it a not statement. Spaces before and after [] are important.
if [ ! -f ~/Desktop/file.txt ]; then
    echo "File not found!"
fi
# Source vs ./
# Runs the script as an executable file, launching a new shell to run it
./script

# Reads and executes commands from filename in the current shell environment
source script
# need to wrap the cd command inside () to run it in scope of the cd
# i.e. pod install will be run inside ios dir
(cd ios && pod install)