feat: first version of examples

This commit is contained in:
kuchy 2022-04-08 05:03:49 +02:00
parent 871937406b
commit 868dd14e14
5 changed files with 125 additions and 32 deletions

Binary file not shown.

View File

@ -3,7 +3,6 @@
# simple version
# the name of the script without a path
name=`basename $0`
help()
{
@ -26,6 +25,15 @@ uppercase()
error_msg "missing filename for -u"
exit 1
fi
if test -f "$1"
then
if test -d "$1"
then
error_msg "$1 is neither a file nor folder"
exit 3
fi
fi
mv "$1" $(echo "$1" | sed -r -e 's/.*/\U&/');
@ -62,8 +70,15 @@ sneed()
error_msg "missing sed filename"
exit 2
fi
echo "$1"
echo $1
if test -f "$2"
then
if test -d "$2"
then
error_msg "$2 is neither a file nor folder"
exit 3
fi
fi
mv "$2" $(echo "$2" | sed $1)
}
@ -80,24 +95,30 @@ recursionSneed()
error_msg "missing sed filename"
exit 2
fi
if test -d "$2"
then
sneed "$1" "$2"
cd "$2"
for file in *
if test -f "$2"
then
if test -d "$2"
then
error_msg "$2 is neither a file or folder"
exit 3
fi
fi
filename="$2"
sneed "$1" "$filename"
filename="$(echo "$filename" | sed $1)"
echo $filename
for item in "$filename"/*
do
recursionSneed "$1" "$file"
if test -d "$item"
then
recursionSneed "$1" "$item"
fi
if test -f "$item"
then
sneed "$1" "$item"
fi
done
fi
if test -f "$2"
then
sneed "$1" "$2"
fi
}
recursionLowercase()
@ -120,7 +141,7 @@ recursionLowercase()
recursionUppercase()
{
uppercase "$1"
set "$(echo "$1" | sed -r -e 's/.*/\L&/')"
set "$(echo "$1" | sed -r -e 's/.*/\U&/')"
for item in "$1"/*
do
if test -d "$item"
@ -158,7 +179,6 @@ error_msg()
echo "$name: error: $1" 1>&2
}
# function for servicing -w option
# if no arguments given
@ -169,17 +189,13 @@ fi
# do with command line arguments
while test "x$1" != "x"
do
case "$1" in
-h|--help) help;;
-l|--lowercase) lowercase "$2";;
-r|--recursion) recursion "$2" "$3" ;;
-u|--upercase) uppercase "$2";;
*) sneed "$1" "$2" ;;
esac
shift
done
case "$1" in
-h|--help) help;;
-l|--lowercase) lowercase "$2";;
-r|--recursion) recursion "$2" "$3" ;;
-u|--upercase) uppercase "$2";;
*) sneed "$1" "$2" ;;
esac

77
EOPSY/task1/modify_examples.sh Normal file → Executable file
View File

@ -0,0 +1,77 @@
#!/bin/bash
touch a
touch B
touch SED
mkdir foldera
mkdir FOLDERB
mkdir FOLDERSED
mkdir upperfoldermain
cd upperfoldermain
touch upperfilesub
mkdir upperfoldersub
cd upperfoldersub
touch upperfilesubsub
cd ..
cd ..
mkdir LOWERCASEFOLDERMAIN
cd LOWERCASEFOLDERMAIN
touch LOWERFILESUB
mkdir LOWERFOLDERSUB
cd LOWERFOLDERSUB
touch LOWERFILESUBSUB
cd ..
cd ..
mkdir SEDLOWERCASEFOLDERMAIN
cd SEDLOWERCASEFOLDERMAIN
touch SEDLOWERFILESUB
mkdir SEDLOWERFOLDERSUB
cd SEDLOWERFOLDERSUB
touch SEDLOWERFILESUBSUB
cd ..
cd ..
touch recursefile
touch RECURSELOWERFILE
touch SEDRECURSEFILE
echo "Typical scenarios"
echo "Uppercasing file with filename a"
echo "Lowercasing file with filename B"
echo "Using sed pattern for lowercasing of file with filename SED"
echo "Uppercasing folder with name foldera non recursively"
echo "Lowercasing folder with name FOLDERB non recursively"
echo "Using sed pattern for lowercasing of folder with name FOLDERSED non recursively"
echo "Uppercasing folder recursively"
echo "Main folder name: upperfoldermain"
echo "folder contains: folder named upperfoldersub , file named upperfilesub"
echo "subfolder upperfoldersub contains file named upperfilesubsub"
echo "Lowercasing folder recursively"
echo "Main folder name: LOWERFOLDERMAIN"
echo "folder contains: folder named LOWERFOLDERSUB , file named LOWERFILESUB"
echo "subfolder LOWERFOLDERSUB contains file named LOWERFILESUBSUB"
echo "using sed pattern for Lowercasing folder recursively"
echo "Main folder name: SEDLOWERFOLDERMAIN"
echo "folder contains: folder named SEDLOWERFOLDERSUB , file named SEDLOWERFILESUB"
echo "subfolder SEDLOWERFOLDERSUB contains file named SEDLOWERFILESUBSUB"
echo "Uncommon scenarios"
echo "uppercasing recursively normal file recursefile"
echo "lowercasing recursively normal file RECURSELOWERFILE"
echo "using sed pattern recursively for normal file to lowercase it SEDRECURSEFILE"
echo "Incorrect scenarios"
echo "not providing enough arguments"
echo "not providing file"
echo "not providing argument for recursion"
echo "provding filename/foldername for file/folder which does not exist"