From c2a787eb44aba791c4bd8860d16f2c7b146488d4 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Mon, 9 Dec 2019 22:30:42 +0200 Subject: [PATCH] BAEL-3370: Cleaned up examples --- linux-bash/read/src/main/{ => bash}/file.csv | 0 .../read/src/main/{ => bash}/read_inputs.sh | 91 +++---------------- linux-bash/read/src/main/dummy_file | 7 -- 3 files changed, 15 insertions(+), 83 deletions(-) rename linux-bash/read/src/main/{ => bash}/file.csv (100%) rename linux-bash/read/src/main/{ => bash}/read_inputs.sh (60%) delete mode 100644 linux-bash/read/src/main/dummy_file diff --git a/linux-bash/read/src/main/file.csv b/linux-bash/read/src/main/bash/file.csv similarity index 100% rename from linux-bash/read/src/main/file.csv rename to linux-bash/read/src/main/bash/file.csv diff --git a/linux-bash/read/src/main/read_inputs.sh b/linux-bash/read/src/main/bash/read_inputs.sh similarity index 60% rename from linux-bash/read/src/main/read_inputs.sh rename to linux-bash/read/src/main/bash/read_inputs.sh index 3e071133aa..c39f77f217 100755 --- a/linux-bash/read/src/main/read_inputs.sh +++ b/linux-bash/read/src/main/bash/read_inputs.sh @@ -1,5 +1,18 @@ #!/bin/bash +# section 2.1 +default_read() { + read input1 input2 input3 + echo "[$input1] [$input2] [$input3]" +} + +# section 2.2 +custom_ifs_no_array(){ + IFS=";" + read input1 input2 input3 + echo "[$input1] [$input2] [$input3]" +} + # Section 2.3 prompt_read_password(){ prompt="You shall not pass:" @@ -17,19 +30,6 @@ array_read() { done } -# section 2.2 -custom_ifs_no_array(){ - IFS=";" - read input1 input2 input3 - echo "[$input1] [$input2] [$input3]" -} - -# section 2.1 -default_read() { - read input1 input2 input3 - echo "[$input1] [$input2] [$input3]" -} - # section 3.1 file_read(){ exec {file_descriptor}<"./file.csv" @@ -43,7 +43,7 @@ file_read(){ } # section 3.2 -advanced_pipeing(){ +command_pipe(){ ls -ll | { declare -a input read while read -a input; @@ -68,65 +68,4 @@ exactly_n_read(){ read -p "$prompt" -N 11 -t 5 input1 input2 echo -e "\ninput word1 [$input1]" echo "input word2 [$input2]" -} - - -advanced_pipeing_ps(){ -# process substitution - declare -a input - while read -a input - do - echo "${input[0]} ${input[8]}" - done < <(ls -ll) -} - -custom_ifs_read(){ - declare -a input_array - while IFS=";" read -a input_array -r - do - for element in ${input_array[@]} - do - echo -n "$element.backup " - done - echo "" - done < "file.csv" -} - -infinite_read(){ - while read -d "?" -ep "Input:" input - do - echo "$input" - done -} - -custom_ifs(){ - declare -a input_array - IFS=$1 # whitespace - read -a input_array -p "Enter something with delimiter <$1>:" - for input in ${input_array[@]} - do - echo "[$input]" - done -} - - - -#default_read -#array_read -#special_delim -file_read -#prompt_read -#default_input_read -#advanced_pipeing -#custom_ifs_read -#infinite_read -# custom_ifs " " -# custom_ifs ";" -#custom_ifs_no_array - - - - - - - +} \ No newline at end of file diff --git a/linux-bash/read/src/main/dummy_file b/linux-bash/read/src/main/dummy_file deleted file mode 100644 index 4c581fc816..0000000000 --- a/linux-bash/read/src/main/dummy_file +++ /dev/null @@ -1,7 +0,0 @@ -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