[SOLVED] Would like to "echo" a line, "read" reply, then execute the reply: How in bash?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Would like to "echo" a line, "read" reply, then execute the reply: How in bash?
Apologies. I've been out of Unix for 14 years, and the gears have rusted. Also, Unix has changed - enough similarities to memory that I'm pretty comfy though.
Glad to see lots of info available via google. However changes are going to take getting used to. Have set up a testbed of 3 nearly identical machines, hoping to make an (at home) private network where I can automate installs and set-ups using NIS and NFS (Similar to work I once did).
Have found useful scripts interspersed with comments, would like to copy and paste them to a bash script that:
Reads the line.
Echos the line.
Reads the reply.
Executes what is typed.
Essentially, by making myself type (or copy & paste) the commands I think I'll become familiar.
Figured I'd use a spreadsheet, select the file, and paste into column B of the spreadsheet. In column A I'd paste:
echo "
and in column C I'd paste:
"
Then I'd cut and paste into a text document, insert the lines:
read A
$A
behind every command necessary to the actual task.
Figured I'd have to escape the ' and ".
Ran a test (test.bash):
#!/bin/bash
for i in `seq 1 10`;
do
echo "Enter a command:"
read A
echo "Trying $A"
$A
done
Thanks! eval (oh yeah! I remember that now!) does the trick. Also thanks for the set -xv, which will be useful when the scripts have been modified to fit my situation. Appreciate it!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.