Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
01-19-2010, 03:59 AM
|
#1
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Rep:
|
How to put custom text on Terminal (bash script) ?
This code:
Code:
#! /bin/bash
echo Okay.
echo
Does not do it....
P.S. I want to show my parents what happens when I do:
Code:
sudo make\ me\ a\ sandwich
and have it say "Okay."
(MrCode's profile sig)
Last edited by lupusarcanus; 01-19-2010 at 04:02 AM.
|
|
|
01-19-2010, 04:24 AM
|
#2
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Original Poster
Rep:
|
Well, I just read "man printf" and tried it.
Code:
#! /bin/bash
printf "Okay."
It failed. How do i do this?
|
|
|
01-19-2010, 04:34 AM
|
#3
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
More info needed!
What do you mean by failed?
Are you getting any error message?
How are you trying to run it?
Did you make the file executable?
Code:
chmod +x myscript
./myscript
Evo2.
Last edited by evo2; 01-19-2010 at 04:35 AM.
Reason: More info needed!
|
|
|
01-19-2010, 04:44 AM
|
#4
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Original Poster
Rep:
|
Quote:
Originally Posted by evo2
More info needed!
What do you mean by failed?
Are you getting any error message?
How are you trying to run it?
Did you make the file executable?
Code:
chmod +x myscript
./myscript
Evo2.
|
Here is my goal:
Code:
$ sudo make\ me\ a\ sandwich
[sudo] password for user:
Okay.
I made a file called "make me a sandwich" and put in:
Code:
#! /bin/bash
echo "Okay."
and saved it to my /home/user directory so I don't have to "cd" into anything to make it work.
Then i made it executable:
Code:
chmod u+x /home/user/make\ me\ a\ sandwich
When I executed:
Code:
sudo make\ me\ a\ sandwich
nothing happened.
I also tried the "printf" instead of "echo" and it did not work.
This is what happens:
Code:
user@box~$ sudo make\ me\ a\ sandwich
user@box~$
What is the correct syntax of echo or printf to make it work?
Thanks and sorry, man pages didn't help much
|
|
|
01-19-2010, 04:49 AM
|
#5
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Try breaking this down into its component parts.
Examples:
- What happens if you don't use sudo?
- What happens if you use a file name with no spaces in it?
You should be able to work this out.
Evo2.
|
|
|
01-19-2010, 05:00 AM
|
#6
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Original Poster
Rep:
|
nevermind, I had to define the full file path, even though I was in the directory where the file is...
Code:
user@box:~$ ~/make\ me\ a\ sandwich
Okay.
Well, It made me my sandwich, but it looks really ugly.
How can I make it so all I have to type is:
Code:
make me a sandwich
or
make_me_a_sandwich
instead of the ~/make_me_a_sandwich?
|
|
|
01-19-2010, 05:13 AM
|
#7
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
I noticed this about your script:
There should not be a space between #! and /bin/bash. It should be #!/bin/bash.
The ./ (dot slash) tells bash "in this directory". You need it if the directory in question is not in your PATH environment variable. If you add your home directory to your PATH, you won't need the ./ Then, because of the spaces in the file name, just add quotes around the file name: "make me a sandwich"
PATH=$PATH: /home/<username>, where <username> is your user name.
|
|
|
01-19-2010, 05:19 AM
|
#8
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Quote:
Originally Posted by bigrigdriver
There should not be a space between #! and /bin/bash. It should be #!/bin/bash.
|
Actually, IIRC some BSDs require the space, while Linux is indifferent to it. For that reason many people reccommed adding the space to ease portability.
Evo2.
|
|
|
01-19-2010, 05:31 AM
|
#9
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Can't believe I did this...
Code:
.SILENT:
all:
echo "Make what?"
me_a_sandwich:
echo "Okay."
Put that in a file called Makefile. Be sure to use a tab to indent.
Then
Evo2.
|
|
|
01-19-2010, 06:52 AM
|
#10
|
LQ 5k Club
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,311
Rep:
|
If you're old enough to be writing bash scripts, you're old enough to make your own sandwiches.
|
|
|
01-19-2010, 07:58 AM
|
#11
|
Moderator
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,971
|
Hi,
Unless you include 'Please'.
|
|
|
01-19-2010, 08:29 AM
|
#12
|
Senior Member
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Original Poster
Rep:
|
everything works. very nice!
Lets see Windows make me a sandwich!
|
|
|
All times are GMT -5. The time now is 02:38 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|