Interactive script to give user option of what text to add
Hello all,
I have created a script that will remove the first two lines of one text file (body.txt) and then add the text from a different text file (header.txt) directly to the beginning of the freshly modified body.txt file. It is as follows:
I want to add the option to this script of letting the user choose which header to add. Let us say that there are four possible headers that one could add i.e. head1.txt, head2.txt, head3.txt and head4.txt and that these files are all located in /home/$USER/.
How would I go about modifying my script in such a way to so that the user would be prompted to chose one of these i.e., when they run the script, they get and must choose either the number 1, 2, 3 or 4.
Once the user has chosen the number, then the script runs and uses the one that they chose, rather than the specific one I have in my file. I would also like it if the only values the numbers 1 through 4 would be accepted.
That works. Although there is about a 10 second pause before the script pops up the menu.
Thanks very much!
Quote:
Originally Posted by ahamed101
Try this
If your sed version supports "-i" option, then you can use the sed command like this sed -i '1,2d' body.txt. This will modify the file directly.
regards,
Ahamed
---------- Post updated at 02:11 PM ---------- Previous update was at 02:00 PM ----------
My next question is what if the menu options are NOT the names of the actual files?
That is, the menu option is a descriptive name and the number that the user presses determines which file it should use.
How does one pass the variable to the cat command?
Instead of:
I have
where
1. Optimization with ZMAT corresponds to the file name "opt_zmat_head.txt"
2. Optimation with Cartesian corresponds to the file name "opt_cart_head.txt"
3. Frequency corresponds to the file name "freq_head.txt"
4. Transition State Search corresponds to the file name "TS_search.txt"
All of these files would be located in /home/$USER/.
---------- Post updated at 03:15 PM ---------- Previous update was at 02:11 PM ----------
Answered my own question...thanks to all who helped out.
Quote:
Originally Posted by marcozd
That works. Although there is about a 10 second pause before the script pops up the menu.
Thanks very much!
---------- Post updated at 02:11 PM ---------- Previous update was at 02:00 PM ----------
My next question is what if the menu options are NOT the names of the actual files?
That is, the menu option is a descriptive name and the number that the user presses determines which file it should use.
How does one pass the variable to the cat command?
Instead of:
I have
where
1. Optimization with ZMAT corresponds to the file name "opt_zmat_head.txt"
2. Optimation with Cartesian corresponds to the file name "opt_cart_head.txt"
3. Frequency corresponds to the file name "freq_head.txt"
4. Transition State Search corresponds to the file name "TS_search.txt"
All of these files would be located in /home/$USER/.
Hello, I want to start out by saying that I am fairly new to scripting and am looking for someone that can point me in the right direction.
Basically what I need is a way to run a interactive script that will prompt users with questions weather that be yes/no or a specific answer.. I want to be... (3 Replies)
Hello,
I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file.
For example;-
In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Hi,
I have a script that calles some other scripts. Those scripts are expecting some inputs.
Right no I am typing manually. But now the number of questions from other scripts are too much and I want to give asnwers autimatically.
example.
Other scripts gives me 2 options
1) joom... (2 Replies)
Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines.
It then prompts for deletion of the file.
If user supplies arguments with the script , then it works on those files... (8 Replies)
Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines.
It then prompts for deletion of the file.
If user supplies arguments with the script , then it works on those files... (1 Reply)
Is is possible switch user from a non-root user to root user without entering the password interactively inside a korn shell script which is run by a non-root user?
e.g. I have a non-root user called infodba who is in dba group and I want to create a shell script which is executed by infodba... (5 Replies)
Hi everybody,
Do you know how to hide the text for interactive unix shell script? Just like the case for inputting password during logon.
Patrick (1 Reply)
Hi All,
sftp -b script.txt <hostname>
user-authentication through non-interactive way is desired. But, its failing to do so.
Could anyone kindly advise.
Thanks for any/all help at the earliest.
Regards,
Dheeraj. (1 Reply)
Hi All,
How can i give permission for a specific user ( eg. admin ) ?
I tried with chmod admin+r prog.sh
which doesnt work.
Is there any way i can specify a user's name and give the permission?
Thanks in advance.
Saneesh Joseph. (1 Reply)