2019-12-01 16:00:04 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-12-05 17:26:42 -05:00
|
|
|
# Section 2.3
|
|
|
|
prompt_read_password(){
|
|
|
|
prompt="You shall not pass:"
|
|
|
|
read -p "$prompt" -s input
|
|
|
|
echo -e "\ninput password [$input]"
|
2019-12-01 16:00:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
array_read() {
|
|
|
|
declare -a input_array
|
2019-12-05 17:26:42 -05:00
|
|
|
text="baeldung is a cool tech site"
|
|
|
|
read -e -i "$text" -a input_array
|
2019-12-01 16:00:04 -05:00
|
|
|
for input in ${input_array[@]}
|
|
|
|
do
|
2019-12-05 17:26:42 -05:00
|
|
|
echo " word [$input]"
|
2019-12-01 16:00:04 -05:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-12-05 17:26:42 -05:00
|
|
|
# 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]"
|
2019-12-01 16:00:04 -05:00
|
|
|
}
|
|
|
|
|
2019-12-05 17:26:42 -05:00
|
|
|
# section 3.1
|
2019-12-01 16:00:04 -05:00
|
|
|
file_read(){
|
2019-12-05 17:26:42 -05:00
|
|
|
exec {file_descriptor}<"./file.csv"
|
2019-12-01 16:00:04 -05:00
|
|
|
declare -a input_array
|
2019-12-05 17:26:42 -05:00
|
|
|
delimiter=";"
|
|
|
|
while IFS="," read -a input_array -d $delimiter -u $file_descriptor
|
2019-12-01 16:00:04 -05:00
|
|
|
do
|
2019-12-05 17:26:42 -05:00
|
|
|
echo "${input_array[0]},${input_array[2]}"
|
2019-12-01 16:00:04 -05:00
|
|
|
done
|
|
|
|
exec {file_descriptor}>&-
|
|
|
|
}
|
|
|
|
|
2019-12-05 17:26:42 -05:00
|
|
|
|
2019-12-01 16:00:04 -05:00
|
|
|
|
|
|
|
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(){
|
2019-12-05 17:26:42 -05:00
|
|
|
ls -ll | ( declare -a input
|
|
|
|
while read -a input;
|
|
|
|
do
|
|
|
|
echo "${input[0]} ${input[8]}"
|
|
|
|
done )
|
|
|
|
}
|
2019-12-01 16:00:04 -05:00
|
|
|
|
2019-12-05 17:26:42 -05:00
|
|
|
advanced_pipeing_ps(){
|
|
|
|
# process substitution
|
|
|
|
declare -a input
|
|
|
|
while read -a input
|
|
|
|
do
|
|
|
|
echo "${input[0]} ${input[8]}"
|
|
|
|
done < <(ls -ll)
|
2019-12-01 16:00:04 -05:00
|
|
|
}
|
|
|
|
|
2019-12-03 13:56:35 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-12-05 17:26:42 -05:00
|
|
|
|
|
|
|
|
2019-12-01 16:00:04 -05:00
|
|
|
#default_read
|
|
|
|
#array_read
|
|
|
|
#special_delim
|
2019-12-05 17:26:42 -05:00
|
|
|
file_read
|
2019-12-01 16:00:04 -05:00
|
|
|
#prompt_read
|
|
|
|
#default_input_read
|
2019-12-03 13:56:35 -05:00
|
|
|
#advanced_pipeing
|
|
|
|
#custom_ifs_read
|
|
|
|
#infinite_read
|
2019-12-05 17:26:42 -05:00
|
|
|
# custom_ifs " "
|
|
|
|
# custom_ifs ";"
|
|
|
|
#custom_ifs_no_array
|
2019-12-01 16:00:04 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|