1

As a complete novice to this i am trying to make a Shell Script. This will be driven by a menu with options such as delete file. The part i am scuppered by is for example, when the menu is up, how to get from pressing '1', to actually creating a new file (as this is option 1 on my menu) I appreciate this may not be the easiest of questions to understand as my use of technical terms is limited, however i would appreciate any help. Below is an example of the first section of my menu. I feel once i know where to start i'll be fine Menu

[1] Create File
[2] Delete File
[3] Rename file
2
  • 1
    I'm not very sure that sh or bash is the best tool for that (scripting languages are probably much more adequate). But you need to learn about the read builtin of sh and read tldp.org/LDP/abs/html (which does have shortcomings). Commented Mar 11, 2013 at 18:50
  • It specifically has to be bash for the task ive been asked to complete. Thanks for your reply tho! Commented Mar 11, 2013 at 18:54

2 Answers 2

5

Try doing this for example :

select x in "Create File" "Delete File" "Rename file"; do
    echo "$x choosen"
    break
done

Sample output

1) Create File
2) Delete File
3) Rename file
> 

Search select in the conditional construct paragraph here

Going further

To run some specific tasks with the result of the $x variable, you can use the case statement (like switch in other languages) like this :

case $x in
    Create*) touch file.txt ;;
    Delete*) rm -f file.txt ;;
    Rename*) mv file.txt file_old.txt ;;
esac
Sign up to request clarification or add additional context in comments.

1 Comment

Added case to treat the result
2

You can do it using switch/case statement. Please have a look on the bash manual or look for similar examples on the Web. Just google "switch case shell example"

Good luck

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.