Shell Programming - Delete user input
HI!
I recently started shell programming and my task now is to do a menu display.Currently i am stuck whereby user will input both title and author and it will delete it. function remove book { echo "Enter Title" read title echo "Enter Author" read author } do i have to use sed command? |
Presumably this is Bash?
The following would work in Bash, ksh and posix sh (but not csh or its variants): Code:
function remove_book() First you had a space in your function name "remove book" - I changed that to underscore "remove_book". Setting up commands with spaces in them is begging for trouble. You didn't have the () after the function name and it is required. You didn't have anything calling the function. You must first define it then call it to use it so the final "remove_book" line is what is doing that in my script. You can add verbiage within the function to do the deletion of the book but need to account for how you're going to do that. For example when I ran a test: Enter Title Moby Dick Enter Author Herman Melville Title is: Moby Dick by Author: Herman Melville Notice that both the title and the author include spaces. You might need to do special handling for that in your removal (e.g. say you had a book by Herman Wouk - you'd want to make sure your deletion routine was just looking for Herman.) |
Quote:
Code:
#!/bin/bash |
yea i doing bash.mine is to create a menustyle program whereby once the user select delete,the screen will prompt which author to delete..
@snark1994, pardon me but is it alright to explain the codes from line carryOn onwards,i dun seem to understand:) |
No problem :)
The basic structure is that we're going to go into a loop - ask the user for some input, then act on the input, and then go back to asking for input. However, we want to be able to break out of this loop; so we have a variable "carryOn" which is set to true, and when we want to quit we will change it to false. So we have: Code:
carryOn=true Code:
carryOn=true Code:
carryOn=true |
All times are GMT -5. The time now is 04:11 PM. |