logoISU  

CS469/569 - Linux and Unix Administration and Networking

Spring 2022

Displaying ./code/02-10/h5/c.sh

#!/bin/bash

# (2 points)
# Given a path on the command line, use stat to print the permissions, user and
# group for each path as you use dirname to walk back up the directory tree to
# root (/).
# Example output:
# > ./c.sh 
# drwxr-xr-x   sbaker    users /net/sbaker/469/h/hw5
# drwx------   sbaker    users /net/sbaker/469/h
# drwx------   sbaker    users /net/sbaker/469
# drwx--x--x   sbaker    users /net/sbaker
# drwxr-xr-x     root     root /net
# drwxr-xr-x     root     root /

# Get the path from the first command line argument, if it is not provided, use
# the current working directory (.):

# Use realpath to get the real path:
p=$(realpath .)
echo $p

d=$(dirname $p)
echo $d

d2=$(dirname $d)
s2=$(stat $d2)
echo $s2

# If the path isn't to a directory, use dirname to get the directory name:
if [[ ! -d $1  ]]; then
    echo "not directory";
else
    echo "directory";
fi
    

if [[ "$1" == "/" ]]; then
    echo "done"
else
    echo "not done"
fi

# While the path is not equal to /, loop:

  # Print the permissions, username, groupname, size and path using the stat
  # command.

  # Use dirname to go up one directory:
p=$(dirname "$p")