From 8673e3a460e4fa1abb021697525d170fd4d92831 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Thu, 12 Sep 2019 11:37:21 +0200 Subject: [PATCH] BAEL-3132 - Linux Commands - Loop Through Directories/Folders (#7682) * BAEL-3132 - Linux Commands - Loop Through Directories/Folders * BAEL-3132 - Linux Commands - Loop Through Directories/Folders - update pom description. * BAEL-3132 - Linux Commands - Loop Through Directories/Folders - Add another example using find exec. * BAEL-3132 - Linux Commands - Loop Through Directories/Folders --- linux-bash/loops/src/main/bash/find_directories.sh | 9 +++++++++ linux-bash/loops/src/main/bash/loop_directories.sh | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100755 linux-bash/loops/src/main/bash/find_directories.sh create mode 100755 linux-bash/loops/src/main/bash/loop_directories.sh diff --git a/linux-bash/loops/src/main/bash/find_directories.sh b/linux-bash/loops/src/main/bash/find_directories.sh new file mode 100755 index 0000000000..8a9b20294d --- /dev/null +++ b/linux-bash/loops/src/main/bash/find_directories.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +find . -maxdepth 1 -mindepth 1 -type d -printf '%f\n' + +find . -maxdepth 1 -mindepth 1 -type d | while read dir; do + echo "$dir" +done + +find . -maxdepth 1 -type d -exec echo {} \; \ No newline at end of file diff --git a/linux-bash/loops/src/main/bash/loop_directories.sh b/linux-bash/loops/src/main/bash/loop_directories.sh new file mode 100755 index 0000000000..77e661d710 --- /dev/null +++ b/linux-bash/loops/src/main/bash/loop_directories.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +for dir in */; do + echo "$dir" +done + +for file in *; do + if [ -d "$file" ]; then + echo "$file" + fi +done \ No newline at end of file