Skip to content

Latest commit

 

History

History
131 lines (120 loc) · 2 KB

File metadata and controls

131 lines (120 loc) · 2 KB

if

if (( $# < 3 ))
then
	printf "%b" "Error. Not enough arguments.\n"
	printf "%b" "usage: myscript file1 op file2\n"
	exit 1
elif (( $# > 3 ))

also...

if list; then list; [ elif list; then list; ] ... [ else list; ] fi

or

#!/bin/sh
DIRPLACE=/tmp
INFILE=/home/yucca/amazing.data
OUTFILE=/home/yucca/more.results

if [ -d "$DIRPLACE" ]
then
  cd $DIRPLACE
  if [ -e "$INFILE" ]
  then
	if [ -w "$OUTFILE" ]
	then
	  doscience < "$INFILE" >> "$OUTFILE"
	else
		echo "cannot write to $OUTFILE"
	  fi
	else
		echo "cannot read from $INFILE"
	fi
else
	echo "cannot cd into $DIRPLACE"
fi

-lt : less than -le : less / equal to -gt : greaterthan -ge : greater / equal to -eq : equal -ne : not equal

if [[ "${MYFILENAME}" == *.jpg ]]

GLOBBING

shopt -s extglob
if [[ "$FN" == *.@(jpg|jpeg) ]]

shopt -s : turn on shell options extglob: we can now do extended pattern matching aka patterns seperated by '|' andd grouped by ( )

GLOBBCABULARY

@(...) : just once *(...) : zero or more +(...) : one or more ?(...) : zero or one !(...) : not this but anything else

FILE ...

-b : is a block special device (i..e /dev/sda1) -c : is like /dev/tty -d : is dirr -e : exists -f : is a fle -g : has group ID set -G : owned by user's group -h : is symbolic link -k : sticky bit -N : modified since it was rread -O : owned by user -p : named pipe -r : readable -s : has a size > 0 -S : socket -w : writable -x : executable

LOOP WAVES

WHILE + MATH

while (( COUNT < MAX ))
do
	some stuff
	let COUNT++
done

for filesystem-related conditions:

while [ -z "$LOCKFILE" ]
	do
	some things
done

or for reading input:

while read lineoftext
	do
	process $lineoftext
done

remove files that svn reports with a question mark

svn status mysrc |
while read TAG FN
do
	if [[ $TAG == \? ]]
	then
		echo $FN
		rm -rf "$FN"
	fi
done

dashes : print out X number of any character

dashes :: prints 72 dashes
dashes 50 :: just 50
dashes -c = 50 :: 50 '='s 
dashes -c x :: 72 x's