Menus and Return commands in Shell; Stuck in a loop












0















I have a menu that uses the case command to switch to a sub-menu that then calls to a shell script (.functions) as follows:



. .functions
loop=z
while [ "$loop" = z ]
do
clear
tput cup 3 12; echo "Student Program Information"
tput cup 4 12; echo "==========================="
printf "n"
tput cup 6 12; echo "Sort by: "
tput cup 7 15; echo "L - Last Name"
tput cup 8 15; echo "P - Programs "
tput cup 9 15; echo "C - Credits "
tput cup 10 15; echo "Any - ID "
printf "n"
tput cup 12 12; echo "Enter your choice: "
tput cup 12 32; read thing || continue
case $thing in
[Ll]) sort_lname ;;
[Pp]) sort_program ;;
[Cc]) sort_credits ;;
*) sort_ID ;;
esac
done


my .functions file then formats and displays the code like so:



sort_ID()
{
sort -k 1 -t: student_data > sorted_records1;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records1
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_lname()
{
sort -k 2 -t: student_data > sorted_records2;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records2
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_program()
{
sort -k 4 -t: student_data > sorted_records3;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records3
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_credits()
{
sort -k 5 -t: -n student_data > sorted_records4;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records4
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}


What I'd like to happen is that after I have chosen an option and it's displayed, I press enter and am brought back up two menus, since the way it is set up now I am stuck in a loop of viewing my records. Any help is appreciated. Thanks!









share







New contributor




Bob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Had a thought. Is there a way I can tell the script to run a file when pressing enter. So instead of it saying read continue and taking me up one menu, it will just clear and rerun the script to get me back to the starting menu?

    – Bob
    3 mins ago
















0















I have a menu that uses the case command to switch to a sub-menu that then calls to a shell script (.functions) as follows:



. .functions
loop=z
while [ "$loop" = z ]
do
clear
tput cup 3 12; echo "Student Program Information"
tput cup 4 12; echo "==========================="
printf "n"
tput cup 6 12; echo "Sort by: "
tput cup 7 15; echo "L - Last Name"
tput cup 8 15; echo "P - Programs "
tput cup 9 15; echo "C - Credits "
tput cup 10 15; echo "Any - ID "
printf "n"
tput cup 12 12; echo "Enter your choice: "
tput cup 12 32; read thing || continue
case $thing in
[Ll]) sort_lname ;;
[Pp]) sort_program ;;
[Cc]) sort_credits ;;
*) sort_ID ;;
esac
done


my .functions file then formats and displays the code like so:



sort_ID()
{
sort -k 1 -t: student_data > sorted_records1;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records1
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_lname()
{
sort -k 2 -t: student_data > sorted_records2;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records2
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_program()
{
sort -k 4 -t: student_data > sorted_records3;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records3
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_credits()
{
sort -k 5 -t: -n student_data > sorted_records4;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records4
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}


What I'd like to happen is that after I have chosen an option and it's displayed, I press enter and am brought back up two menus, since the way it is set up now I am stuck in a loop of viewing my records. Any help is appreciated. Thanks!









share







New contributor




Bob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Had a thought. Is there a way I can tell the script to run a file when pressing enter. So instead of it saying read continue and taking me up one menu, it will just clear and rerun the script to get me back to the starting menu?

    – Bob
    3 mins ago














0












0








0








I have a menu that uses the case command to switch to a sub-menu that then calls to a shell script (.functions) as follows:



. .functions
loop=z
while [ "$loop" = z ]
do
clear
tput cup 3 12; echo "Student Program Information"
tput cup 4 12; echo "==========================="
printf "n"
tput cup 6 12; echo "Sort by: "
tput cup 7 15; echo "L - Last Name"
tput cup 8 15; echo "P - Programs "
tput cup 9 15; echo "C - Credits "
tput cup 10 15; echo "Any - ID "
printf "n"
tput cup 12 12; echo "Enter your choice: "
tput cup 12 32; read thing || continue
case $thing in
[Ll]) sort_lname ;;
[Pp]) sort_program ;;
[Cc]) sort_credits ;;
*) sort_ID ;;
esac
done


my .functions file then formats and displays the code like so:



sort_ID()
{
sort -k 1 -t: student_data > sorted_records1;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records1
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_lname()
{
sort -k 2 -t: student_data > sorted_records2;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records2
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_program()
{
sort -k 4 -t: student_data > sorted_records3;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records3
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_credits()
{
sort -k 5 -t: -n student_data > sorted_records4;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records4
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}


What I'd like to happen is that after I have chosen an option and it's displayed, I press enter and am brought back up two menus, since the way it is set up now I am stuck in a loop of viewing my records. Any help is appreciated. Thanks!









share







New contributor




Bob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have a menu that uses the case command to switch to a sub-menu that then calls to a shell script (.functions) as follows:



. .functions
loop=z
while [ "$loop" = z ]
do
clear
tput cup 3 12; echo "Student Program Information"
tput cup 4 12; echo "==========================="
printf "n"
tput cup 6 12; echo "Sort by: "
tput cup 7 15; echo "L - Last Name"
tput cup 8 15; echo "P - Programs "
tput cup 9 15; echo "C - Credits "
tput cup 10 15; echo "Any - ID "
printf "n"
tput cup 12 12; echo "Enter your choice: "
tput cup 12 32; read thing || continue
case $thing in
[Ll]) sort_lname ;;
[Pp]) sort_program ;;
[Cc]) sort_credits ;;
*) sort_ID ;;
esac
done


my .functions file then formats and displays the code like so:



sort_ID()
{
sort -k 1 -t: student_data > sorted_records1;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records1
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_lname()
{
sort -k 2 -t: student_data > sorted_records2;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records2
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_program()
{
sort -k 4 -t: student_data > sorted_records3;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records3
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}

sort_credits()
{
sort -k 5 -t: -n student_data > sorted_records4;
clear;
awk -F: ' { printf "%-12s %-12s %-12s %-24s %-12sn", $1, $2, $3, $4, $5 } ' sorted_records4
printf "n"
printf "n"
echo "The total number of records: "
wc -l < student_data
printf "n"
echo "Press ENTER to continue..."
read continue
}


What I'd like to happen is that after I have chosen an option and it's displayed, I press enter and am brought back up two menus, since the way it is set up now I am stuck in a loop of viewing my records. Any help is appreciated. Thanks!







linux shell-script shell





share







New contributor




Bob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share







New contributor




Bob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share



share






New contributor




Bob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 7 mins ago









BobBob

1




1




New contributor




Bob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Bob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Bob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Had a thought. Is there a way I can tell the script to run a file when pressing enter. So instead of it saying read continue and taking me up one menu, it will just clear and rerun the script to get me back to the starting menu?

    – Bob
    3 mins ago



















  • Had a thought. Is there a way I can tell the script to run a file when pressing enter. So instead of it saying read continue and taking me up one menu, it will just clear and rerun the script to get me back to the starting menu?

    – Bob
    3 mins ago

















Had a thought. Is there a way I can tell the script to run a file when pressing enter. So instead of it saying read continue and taking me up one menu, it will just clear and rerun the script to get me back to the starting menu?

– Bob
3 mins ago





Had a thought. Is there a way I can tell the script to run a file when pressing enter. So instead of it saying read continue and taking me up one menu, it will just clear and rerun the script to get me back to the starting menu?

– Bob
3 mins ago










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Bob is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495207%2fmenus-and-return-commands-in-shell-stuck-in-a-loop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








Bob is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Bob is a new contributor. Be nice, and check out our Code of Conduct.













Bob is a new contributor. Be nice, and check out our Code of Conduct.












Bob is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495207%2fmenus-and-return-commands-in-shell-stuck-in-a-loop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

宮崎県

濃尾地震

シテ島