From d7df6949a7ba876de2f8a62f455ce266112b4021 Mon Sep 17 00:00:00 2001 From: khagapati-bagh Date: Fri, 1 Oct 2021 23:02:46 +0530 Subject: [PATCH 1/3] Added different style of using for loop in bash --- bash/for_loop.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 bash/for_loop.sh diff --git a/bash/for_loop.sh b/bash/for_loop.sh new file mode 100644 index 0000000..83dc762 --- /dev/null +++ b/bash/for_loop.sh @@ -0,0 +1,19 @@ +#!/bin/bash +echo "Different style of using for loop" +echo -e "\nStyle #1" +words="This is the right place to learn and sahre your skills" +for word in $words + do + echo $word + done +echo -e "\nStyle #2" +for word in Directly accessing value + do + echo $word + done +echo -e "\nStyle #3" +for ((i = 1; i <= 10; i++)) + do + echo $i | tr '\n' ' ' + done +echo -e "\n\nThank You" From 792176033fc1e295b03c4d9572be2ce7cc013f74 Mon Sep 17 00:00:00 2001 From: khagapati-bagh Date: Sat, 2 Oct 2021 11:00:22 +0530 Subject: [PATCH 2/3] Added usage of case in bash --- bash/case.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 bash/case.sh diff --git a/bash/case.sh b/bash/case.sh new file mode 100644 index 0000000..44af2d5 --- /dev/null +++ b/bash/case.sh @@ -0,0 +1,13 @@ +#!/bin/bash +echo "Do you know how to contribute to open source projects?" +read -p "Yes/No: " response +case $response in + Yes|yes|YES) + echo "Thats great, you can also contribute to this repo" + ;; + No|no|NO) + echo "You can follow this https://github.com/firstcontributions/first-contributions" + echo "Then come back here and start contributing" + ;; +esac +echo -e "\n\nThank You" From 153fb088abcee590bdcc27563cfe2721cc8c5bb6 Mon Sep 17 00:00:00 2001 From: khagapati-bagh Date: Sat, 2 Oct 2021 22:46:59 +0530 Subject: [PATCH 3/3] Added script to read from a file and write to a file --- bash/text_file.txt | 11 +++++++++++ bash/write_to_a_file.sh | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 bash/text_file.txt create mode 100644 bash/write_to_a_file.sh diff --git a/bash/text_file.txt b/bash/text_file.txt new file mode 100644 index 0000000..9941258 --- /dev/null +++ b/bash/text_file.txt @@ -0,0 +1,11 @@ +total 9 +-rwxr-xr-x 1 Khagapati 197121 391 Oct 2 09:50 arithmatic.sh +-rwxr-xr-x 1 Khagapati 197121 418 Oct 2 10:59 case.sh +-rwxr-xr-x 1 Khagapati 197121 403 Oct 1 23:09 for_loop.sh +-rwxr-xr-x 1 Khagapati 197121 33 Oct 1 22:58 hello_world.sh +-rwxr-xr-x 1 Khagapati 197121 86 Oct 2 22:46 read_from_a_file.sh +-rw-r--r-- 1 Khagapati 197121 0 Oct 2 22:46 text_file.txt +-rwxr-xr-x 1 Khagapati 197121 138 Oct 1 22:58 use_echo.sh +-rwxr-xr-x 1 Khagapati 197121 83 Oct 1 22:58 user_input.sh +-rwxr-xr-x 1 Khagapati 197121 125 Oct 1 22:58 while_loop.sh +-rwxr-xr-x 1 Khagapati 197121 130 Oct 2 22:45 write_to_a_file.sh diff --git a/bash/write_to_a_file.sh b/bash/write_to_a_file.sh new file mode 100644 index 0000000..882998b --- /dev/null +++ b/bash/write_to_a_file.sh @@ -0,0 +1,6 @@ +#!/bin/bash +#Create output file, override if already present +output=text_file.txt + +#Write data to a file +ls -l> $output