User Tools

Site Tools


journal:spring2019:bmather2:week6

Unix Week6


Feb 26- Mar 5, 2019

Extended Command Mode -':' this enters this mode

-'set' commands

-'number' gives line numbers without adding them to the file itself
-'tabstop=(number)' sets tab length usually should be 4
-'shiftwidth=(number)' something else to do with formating, usually the same as tabstop length
-'smartindent' auto indents code
-'cursorcolumn' highlights the current column
-'cursorline' highlights the current line

Other commands
-'syntax on' color coded based on the file type

-'colorscheme (scheme)' you can tab thru the options

-'(number[,range])copy(number)' copies the first number line to the line after the second number

-'move' works the same ^^

-'(range % does all)s/(search)/(replacement)/' search and replace (normally only does it for the first occurrence, add g to do it for all)

can use regular expressions like '.' (all) '[a-z]' (all lowercase letters)

-'r' read in the contents of whatever you specify

-'help'

Tips
You can add a no before some of these to turn off (i.e. smartindent)

You can call vi with more than one file to open all then cycle through with :n and :N

~/.vimrc is a config file so you can have certain settings run every time you open vi

Shell scripting

start with '#!/bin/bash' this makes sure bash runs the script

for math operations
-eq
-ne
-gt
-lt
-ge
-le

If statement

if [ condition ]; then
#commands
elif[another condition]; then
# if preceding conditions are false commands
else
#do this if nothing is true
fi

Spacing Matters
When comparing vars, spaced comparison sign
When assigning vars, no spaces near assignment operator

Other Notes

Remember:
For loops preserve their variable outside the loop (so be mindful of naming)

How to generate a random number
${RANDOM}

(Between 1 and 100)
$((${RANDOM}%100+1))

How to receive input
read (var for storage)

- 'break' will break a loop in the middle

Double parentheses is a pocket of arithmetic

How to check for additional command line inputs
if [ ! -z “${1}” ]; then (if the additional argument is not nothing)

journal/spring2019/bmather2/week6.txt · Last modified: 2019/03/05 16:13 by bmather2