add exercises 7 and 8
This commit is contained in:
0
shell_scripting_succinctly/exercise6.sh
Normal file → Executable file
0
shell_scripting_succinctly/exercise6.sh
Normal file → Executable file
19
shell_scripting_succinctly/exercise7.sh
Executable file
19
shell_scripting_succinctly/exercise7.sh
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Prompts the user for a file or directory name and reports if it is
|
||||||
|
# a regular file or directory.
|
||||||
|
# Also performs an 'ls' long listing command against the file or directory.
|
||||||
|
|
||||||
|
# Main body of shell script starts here.
|
||||||
|
FD_NAME=$1
|
||||||
|
|
||||||
|
if [ -f $FD_NAME ]
|
||||||
|
then
|
||||||
|
echo "${FD_NAME} is a regular file or directory."
|
||||||
|
ls -l $FD_NAME
|
||||||
|
else
|
||||||
|
echo "${FD_NAME} is NOT a regular file or directory."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Exit with an explicit exit status.
|
||||||
|
exit 0
|
||||||
25
shell_scripting_succinctly/exercise8.sh
Executable file
25
shell_scripting_succinctly/exercise8.sh
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Prompts the user for a file or directory name and reports if it is
|
||||||
|
# a regular file or directory.
|
||||||
|
# Also performs an 'ls' long listing command against the file or directory.
|
||||||
|
|
||||||
|
# Main body of shell script starts here.
|
||||||
|
|
||||||
|
for PARAM in $@
|
||||||
|
do
|
||||||
|
if [ -f $PARAM ]
|
||||||
|
then
|
||||||
|
echo "${PARAM} is a regular file."
|
||||||
|
elif [ -d $PARAM]
|
||||||
|
then
|
||||||
|
echo "${PARAM} is a regular directory."
|
||||||
|
else
|
||||||
|
echo "${PARAM} is NOT a regular file or directory."
|
||||||
|
fi
|
||||||
|
|
||||||
|
ls -l $PARAM
|
||||||
|
done
|
||||||
|
|
||||||
|
# Exit with an explicit exit status.
|
||||||
|
exit 0
|
||||||
Reference in New Issue
Block a user