#!/bin/bash function check_dirs() { for i in $* do check_dir $i done } function check_dir() { if [ -d $1 ] then return 0 else usage "$1 is not a directory" fi } function check_permissions() { if ! [ -r $1 ] then usage "You do not have read permissions on $1" elif ! [ -w $2 ] then usage "You do not have write permissions on $2" fi for i in `ls $1` do if ! [ -r $1$i ] then usage "You do not have read permissions on $1$i" fi done for i in `ls $2` do if ! [ -w $2$i ] then usage "You do not have write permissions on $2$i" fi done } function copy_files() { for i in `ls $1` do if [ -f $1$i ] then #it is a file not a dir cp $1$i $2$i fi done } function usage() { echo Error: $1 echo Usage: assign1 source_dir dest_dir exit } function check_args() { if [ $# != 2 ] then usage "There need to be exactly two command line arguments" fi } check_args $* check_dirs $* check_permissions $* copy_files $*