BAEL-3370: Organized the sample scripts
This commit is contained in:
parent
d64771257a
commit
5614955b13
@ -1,2 +1 @@
|
|||||||
lorem;ipsum;is\;simply\;du\mmy;text
|
car,car model,car year,car vin;Mercury,Grand Marquis,2000,2G61S5S33F9986032;Mitsubishi,Truck,1995,SCFFDABE1CG137362;Ford,Mustang,1968,2G4WS55J351278031;Ford,Crown Victoria,1996,4T1BK1EB8EU586249;GMC,Envoy,2004,WVGEF9BP3FD720618;
|
||||||
of;the;printing;and;typesetting;industry.
|
|
||||||
|
|
@ -1,50 +1,48 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Section 2.3
|
||||||
default_read() {
|
prompt_read_password(){
|
||||||
echo "Please enter something:"
|
prompt="You shall not pass:"
|
||||||
read first second third
|
read -p "$prompt" -s input
|
||||||
echo "first word [$first]"
|
echo -e "\ninput password [$input]"
|
||||||
echo "second word [$second]"
|
|
||||||
echo "third word [$third]"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
array_read() {
|
array_read() {
|
||||||
declare -a input_array
|
declare -a input_array
|
||||||
echo "Please enter something:"
|
text="baeldung is a cool tech site"
|
||||||
read -a input_array
|
read -e -i "$text" -a input_array
|
||||||
for input in ${input_array[@]}
|
for input in ${input_array[@]}
|
||||||
do
|
do
|
||||||
echo " Word [$input]"
|
echo " word [$input]"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
special_delim() {
|
# section 2.2
|
||||||
echo "Please enter something:"
|
custom_ifs_no_array(){
|
||||||
read -d ";" first second third
|
IFS=";"
|
||||||
echo "first word [$first]"
|
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(){
|
file_read(){
|
||||||
# open file descriptor for reading
|
exec {file_descriptor}<"./file.csv"
|
||||||
exec {file_descriptor}<"./dummy_file"
|
|
||||||
declare -a input_array
|
declare -a input_array
|
||||||
echo "Reading first line from file"
|
delimiter=";"
|
||||||
read -a input_array -u $file_descriptor
|
while IFS="," read -a input_array -d $delimiter -u $file_descriptor
|
||||||
for input in ${input_array[@]}
|
|
||||||
do
|
do
|
||||||
echo " Word [$input]"
|
echo "${input_array[0]},${input_array[2]}"
|
||||||
done
|
done
|
||||||
# close file descriptor after reading
|
|
||||||
exec {file_descriptor}>&-
|
exec {file_descriptor}>&-
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_read(){
|
|
||||||
echo "With prompt :"
|
|
||||||
prompt="You shall not pass:"
|
|
||||||
read -p "$prompt" input
|
|
||||||
echo "word -> [$input]"
|
|
||||||
}
|
|
||||||
|
|
||||||
default_input_read(){
|
default_input_read(){
|
||||||
echo "Default input read:"
|
echo "Default input read:"
|
||||||
@ -55,17 +53,20 @@ default_input_read(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
advanced_pipeing(){
|
advanced_pipeing(){
|
||||||
ls | (read -p "Input from ls" input; echo "Single read -> [$input]")
|
ls -ll | ( declare -a input
|
||||||
ls | (while IFS= read input;
|
while read -a input;
|
||||||
do
|
do
|
||||||
echo "$input"
|
echo "${input[0]} ${input[8]}"
|
||||||
done )
|
done )
|
||||||
# process substitution
|
}
|
||||||
while read input
|
|
||||||
do
|
|
||||||
echo "$input"
|
|
||||||
done < <(ls)
|
|
||||||
|
|
||||||
|
advanced_pipeing_ps(){
|
||||||
|
# process substitution
|
||||||
|
declare -a input
|
||||||
|
while read -a input
|
||||||
|
do
|
||||||
|
echo "${input[0]} ${input[8]}"
|
||||||
|
done < <(ls -ll)
|
||||||
}
|
}
|
||||||
|
|
||||||
custom_ifs_read(){
|
custom_ifs_read(){
|
||||||
@ -97,17 +98,20 @@ custom_ifs(){
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#default_read
|
#default_read
|
||||||
#array_read
|
#array_read
|
||||||
#special_delim
|
#special_delim
|
||||||
#file_read
|
file_read
|
||||||
#prompt_read
|
#prompt_read
|
||||||
#default_input_read
|
#default_input_read
|
||||||
#advanced_pipeing
|
#advanced_pipeing
|
||||||
#custom_ifs_read
|
#custom_ifs_read
|
||||||
#infinite_read
|
#infinite_read
|
||||||
custom_ifs " "
|
# custom_ifs " "
|
||||||
custom_ifs ";"
|
# custom_ifs ";"
|
||||||
|
#custom_ifs_no_array
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user