Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Could you please tell us what do you exactly have in mind with this script? I mean, strictly speaking, just
Code:
echo -e "\tHello $name , bye"
would be enough to fulfill your request. Is that $(echo "Hello " $name) just a placeholder for commands you want to put into the real script? Then what would they be?
Thank you to everybody so far but I still looking for help.
Thank you to pan64. You give me some right tips.Your code worked partially.
I modified the code in this way:
echo -e "\t\tPlease enter your name?"
read name
name="${name,,}"
for i in $(echo "Hello " $name) ; do echo ${i^} ; done | sed 's/^/\t\t/;s/$/, here is your order:/'
If I enter the name like : mike denver
The output is:
<here come out the right space of two tabs>Hello, here is your order:
<here come out the right space of two tabs>Mike, here is your order:
<here come out the right space of two tabs>Denver, here is your order:
Basically, it create the right space from the left side based on the number of tabs that I put (\t), but it repeats the print line for Hello plus for each names entered. I didn't understand how to put sed command outside.
My expected result should be this:
<here come out the right space of two tabs>Hello, Mike Denver here is your order:
A for loop is a programming statement that allows a section of code to repeat. A bash for loop can iterate over a list or a sequence and in the case of your program it is a list that is created using your command $(echo "Hello" $name). The default separator for a list is a space and if you enter multiple names your loop will be a list like
hello
first name ( mike )
second name ( denver )
And create a line here is your order for each item in the list as posted above and as shown in your output. I assume this is homework and while we should not write the script for you we can try to help with specific problems. I'm not sure your on the right track without seeing the actual assignment.
Anyway, I would like to explain that if I am doing this research, is because I am still learning Unix and I am asking help, just because I am creating my personal code and I would like to make this change even if it is not necessary but I like to learn, and this is the reason because I asked this community help to sort out my curiosity. Thank you anyway for all of you that gave me some of your precious time.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.