From 45f6f4c2616b0098b2fa01d72b65bdf567c9b5ac Mon Sep 17 00:00:00 2001 From: kiruthiga2001 <128132791+kiruthiga2001@users.noreply.github.com> Date: Wed, 6 Nov 2024 06:37:50 -0800 Subject: [PATCH 1/4] kiruthiga MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ex-1 wilcards Write a shell script that renames all files in the current directory that end in ".jpg" to begin with today's date in the following format: YYYY­MM­DD. For example, if a picture of my cat was in the current directory and today was October 31, 2016 it would change name from "mycat.jpg" to "2016­10­31­mycat.jpg". --- wildcards_ex1.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 wildcards_ex1.txt diff --git a/wildcards_ex1.txt b/wildcards_ex1.txt new file mode 100644 index 0000000..ba6d777 --- /dev/null +++ b/wildcards_ex1.txt @@ -0,0 +1,9 @@ +#!/bin/bash +TODAT=$(date +%Y-%m-%d) +for file in *.jpg; +do + if [ -f "$file" ]; then + mv "$file" "${TODAY}-${file}" + echo "Renamed $file to ${TOADY}-${file}" + fi +done \ No newline at end of file From c062f210094c9ac4ed98e7d44e0af6422a0bc33c Mon Sep 17 00:00:00 2001 From: kiruthiga2001 <128132791+kiruthiga2001@users.noreply.github.com> Date: Wed, 6 Nov 2024 06:43:30 -0800 Subject: [PATCH 2/4] function_ex1 Functions Ex-1 Write a shell script that consists of a function that display the number of files in the present working directory. Name this function "file_count" and call it in your script. If you use a variable in your function, remember to make it a local variable. --- function_ex1.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 function_ex1.txt diff --git a/function_ex1.txt b/function_ex1.txt new file mode 100644 index 0000000..be5faa7 --- /dev/null +++ b/function_ex1.txt @@ -0,0 +1,6 @@ +#!/bin/bash +file_count() { + count=$(ls) + echo "There are $count files in present working directory" +} +file_count \ No newline at end of file From 0bb8d694aafc90e498919d695c05c6d30092b478 Mon Sep 17 00:00:00 2001 From: kiruthiga2001 <128132791+kiruthiga2001@users.noreply.github.com> Date: Wed, 6 Nov 2024 06:50:26 -0800 Subject: [PATCH 3/4] exercise5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ex-5 Write a shell script to check to see if the file “file_path” exists. If it does exist, display “file_path passwords are enabled.” Next, check to see if you can write to the file. If you can, display “You have permissions to edit “file_path.””If you cannot, display “You do NOT have permissions to edit “file_path”” --- ex5.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ex5.txt diff --git a/ex5.txt b/ex5.txt new file mode 100644 index 0000000..31cb4ab --- /dev/null +++ b/ex5.txt @@ -0,0 +1,13 @@ +#!/bin/bash +read -p "Enter the file path" File_path +if [ -e "$File_path" ]&&[ -w "$File_path" ]; then + echo "File_path exists password are enabled" +if [ -w "$File_path" ]; +then + echo "you have permission to edit "$File_path"" +else + echo "you do not have a permission to edit "$File_path"" +fi +else + echo "$File_path does not exist" +fi \ No newline at end of file From f8a0f48d67f70eff9dfcf55dd9d6752360df82db Mon Sep 17 00:00:00 2001 From: kiruthiga2001 <128132791+kiruthiga2001@users.noreply.github.com> Date: Wed, 6 Nov 2024 06:53:48 -0800 Subject: [PATCH 4/4] exercise6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ex-6 Write a shell script that displays “man”,”bear”,”pig”,”dog”,”cat”,and “sheep” on the screen with each appearing on a separate line. Try to do this in as few lines as possible. --- ex6.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 ex6.txt diff --git a/ex6.txt b/ex6.txt new file mode 100644 index 0000000..15cefa2 --- /dev/null +++ b/ex6.txt @@ -0,0 +1,6 @@ +#!/bin/bash +ANIMALS=("MAN" "BEAR" "PIG" "DOG" "SHEEP") +for ((i=0; i<=${#ANIMALS[@]}; i++)) +do + echo "${ANIMALS[i]}" +done \ No newline at end of file