From 9bfc0fea1b278db02be6fc9b0478dd6c92e3b6f7 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Sun, 1 Dec 2019 23:00:04 +0200 Subject: [PATCH] BAEL-3370: First examples --- linux-bash/read/src/main/dummy_file | 7 +++ linux-bash/read/src/main/read_inputs.sh | 83 +++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 linux-bash/read/src/main/dummy_file create mode 100755 linux-bash/read/src/main/read_inputs.sh diff --git a/linux-bash/read/src/main/dummy_file b/linux-bash/read/src/main/dummy_file new file mode 100644 index 0000000000..4c581fc816 --- /dev/null +++ b/linux-bash/read/src/main/dummy_file @@ -0,0 +1,7 @@ +Lorem Ipsum is simply dummy text of the printing and typesetting industry. +Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, +when an unknown printer took a galley of type and scrambled it to make a type specimen book. +It has survived not only five centuries, but also the leap into electronic typesetting, +remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset +sheets containing Lorem Ipsum passages, and more recently with desktop publishing software +like Aldus PageMaker including versions of Lorem Ipsum. \ No newline at end of file diff --git a/linux-bash/read/src/main/read_inputs.sh b/linux-bash/read/src/main/read_inputs.sh new file mode 100755 index 0000000000..4351a27e60 --- /dev/null +++ b/linux-bash/read/src/main/read_inputs.sh @@ -0,0 +1,83 @@ +#!/bin/bash + + +default_read() { + echo "Please enter something:" + read first second third + echo "first word [$first]" + echo "second word [$second]" + echo "third word [$third]" +} + +array_read() { + declare -a input_array + echo "Please enter something:" + read -a input_array + for input in ${input_array[@]} + do + echo " Word [$input]" + done +} + +special_delim() { + echo "Please enter something:" + read -d ";" first second third + echo "first word [$first]" +} + +file_read(){ + # open file descriptor for reading + exec {file_descriptor}<"./dummy_file" + declare -a input_array + echo "Reading first line from file" + read -a input_array -u $file_descriptor + for input in ${input_array[@]} + do + echo " Word [$input]" + done + exec {file_descriptor}>&- +} + +prompt_read(){ + echo "With prompt :" + prompt="You shall not pass:" + read -p "$prompt" input + echo "word -> [$input]" +} + +default_input_read(){ + echo "Default input read:" + prompt=$'What\'s up doc: \n' + default_input="Nothing much just killing time" + read -e -p "$prompt" -i "$default_input" actual_input + echo "word -> [$actual_input]" +} + +advanced_pipeing(){ + ls | (read -p "Input from ls" input; echo "Single read -> [$input]") + ls | (while IFS= read input; + do + echo "$input" + done ) + # process substitution + while read input + do + echo "$input" + done < <(ls) + +} + +#default_read +#array_read +#special_delim +#file_read +#prompt_read +#default_input_read +advanced_pipeing + + + + + + +