unix - Bash Script: want to call a function that reads input -
i'm writing script calls on function reads input in multiple lines. want pass parameters read, don't know if can or how to.
aka how enter-grades take values input instead of waiting input @ prompts?
inside bash script
... login="studentname" echo "enter score:" read score echo "comments:" read comments enter-grades $hw #---> calls function (dont know definition) # # want pass parameters enter-grades each read echo "$login" #---> input enter-grade's first read echo "$score $comments" #---> input enter-grade's second read echo "." #---> input enter-grade's third read outside bash script
#calling enter-grades > enter-grades hw2 entering grades assignment hw2. reading previous scores hw2... done. enter grades 1 @ time. end login of '.' login: [reads input here] grade , comments: [reads input here] login: [reads input here]
assuming enter-grades not read directly terminal, supply information on program's standard input:
login="studentname" read -p "enter score: " score read -p "comments: " comments then, group echo commands together, , pass program:
{ echo "$login" echo "$score $comments" echo "." } | enter-grades "$hw" or, succinctly
printf "%s\n" "$login" "$score $comments" "." | enter-grades "$hw" quote all variables.
or, here-doc
enter-grades "$hw" <<end $login $score $comments . end
Comments
Post a Comment