CS计算机代考程序代写 #! /bin/bash

#! /bin/bash
#
# Assignment 2
# Course: UNX510
# Family Name: Student
# Given Name: John
# Student Number: 123-456-789
# Login name: jstudent
# Professor: Shahdad-Shariatmadari
# Due Date: July-18,-2021
#
# I declare that the attached assignment is my own work in
# accordance with Seneca Academic Policy. No part of this
# assignment has been copied manually or electronically from
# any other source (including web sites) or distributed to
# other students.

# Print the header
printHeader(){
echo ” Owner Group Other Filename”
echo ” —– —– —– ——–”
}

# Print information of the given directory
printOneDir(){
baseName=”$1″

# GNU `ls’ uses a `.’ character to indicate a file with an SELinux
# security context, but no other alternate access method.
# Remove the trailing dot in the type-permission field if any.
rawInfo=$(ls -d -l “$baseName” | \
cut -d ‘ ‘ -f 1 | \
sed ‘s/\.$//’)

outInfo=$(echo “$rawInfo” | \
sed ‘s/\(.\)/\1 /g’ | \
sed ‘s/./& /8’ | \
sed ‘s/./& /16’)

# Print the properly formatted file-type/permission string
if echo “$rawInfo” | grep -q “\-\-\-$”; then
# Turn highlighting on if suitable
tput smso
echo “$outInfo $baseName”
tput rmso
else
echo “$outInfo $baseName”
fi
}

# Find the absolute path
getAbsPath(){
pushd “$1” >/dev/null
echo “$PWD”
popd > /dev/null
}

# Check the number of arguments
if [ $# -gt 1 ]; then
echo “Usage: $0 [ dir-name ]”
exit 1
fi

# Check the specified directory
if [ $# -eq 1 ]; then
dirName=”$1″
else
dirName=”$PWD”
fi
if [ ! -d “$dirName” ]; then
echo “$0: $dirName is not a valid directory name”
exit 1
fi

# Find the absolute path
# Current directory should not be changed
absName=$(getAbsPath “$dirName”)

# Print the header
printHeader

# Print the root directory, i.e., “/”
printOneDir “/”
cd /

# Traverse the absolute directory path
for subdir in $(echo “$absName” | sed ‘s/\// /g’); do
# Print each subdir
printOneDir “$subdir”
cd “$subdir”
done