LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

Reply
 
Search this Thread
Old 01-19-2010, 02:59 AM   #1
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Rep: Reputation: 146Reputation: 146
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 03:02 AM.
 
Old 01-19-2010, 03:24 AM   #2
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 146Reputation: 146
Well, I just read "man printf" and tried it.

Code:
#! /bin/bash

printf "Okay."
It failed. How do i do this?
 
Old 01-19-2010, 03:34 AM   #3
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,300

Rep: Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139
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 03:35 AM. Reason: More info needed!
 
Old 01-19-2010, 03:44 AM   #4
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 146Reputation: 146
Quote:
Originally Posted by evo2 View Post
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
 
Old 01-19-2010, 03:49 AM   #5
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,300

Rep: Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139
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.
 
Old 01-19-2010, 04:00 AM   #6
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 146Reputation: 146
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?
 
Old 01-19-2010, 04:13 AM   #7
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,769

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
I noticed this about your script:
Code:
#! /bin/bash
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.
 
Old 01-19-2010, 04:19 AM   #8
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,300

Rep: Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139
Quote:
Originally Posted by bigrigdriver View Post
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.
 
Old 01-19-2010, 04:31 AM   #9
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,300

Rep: Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139
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
Code:
make me_a_sandwich
Evo2.
 
Old 01-19-2010, 05:52 AM   #10
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware & Slackware64 14.1
Posts: 7,022
Blog Entries: 52

Rep: Reputation: Disabled
If you're old enough to be writing bash scripts, you're old enough to make your own sandwiches.
 
Old 01-19-2010, 06:58 AM   #11
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,187
Blog Entries: 3

Rep: Reputation: 1424Reputation: 1424Reputation: 1424Reputation: 1424Reputation: 1424Reputation: 1424Reputation: 1424Reputation: 1424Reputation: 1424Reputation: 1424
Hi,

Unless you include 'Please'.

 
Old 01-19-2010, 07:29 AM   #12
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 146Reputation: 146
everything works. very nice!
Lets see Windows make me a sandwich!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copying text from terminal BASH window to a webpage. mdlinuxwolf Linux - Newbie 4 10-30-2009 07:13 PM
bash script to create text in a file or replace value of text if already exists knightto Linux - Newbie 5 09-10-2008 11:13 PM
Custom startup script for apache - where to put them Swakoo Linux - General 3 08-10-2007 06:11 AM
Bash put script jnusa Programming 3 09-07-2004 02:31 AM
Changing Text Size/Terminal Width in Bash TastyWheat Linux - General 2 11-02-2003 11:24 PM


All times are GMT -5. The time now is 04:53 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration