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

Original Poster
Blog Entries: 19

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, 04:34 AM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726

Rep: Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706
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!
 
Old 01-19-2010, 04:44 AM   #4
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022

Original Poster
Blog Entries: 19

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, 04:49 AM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726

Rep: Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706
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, 05:00 AM   #6
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022

Original Poster
Blog Entries: 19

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, 05:13 AM   #7
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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, 05:19 AM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726

Rep: Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706
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, 05:31 AM   #9
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726

Rep: Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706
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, 06:52 AM   #10
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,311
Blog Entries: 61

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, 07:58 AM   #11
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,971
Blog Entries: 46

Rep: Reputation: 3195Reputation: 3195Reputation: 3195Reputation: 3195Reputation: 3195Reputation: 3195Reputation: 3195Reputation: 3195Reputation: 3195Reputation: 3195Reputation: 3195
Hi,

Unless you include 'Please'.

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

Original Poster
Blog Entries: 19

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 08:13 PM
bash script to create text in a file or replace value of text if already exists knightto Linux - Newbie 5 09-11-2008 12:13 AM
Custom startup script for apache - where to put them Swakoo Linux - General 3 08-10-2007 07:11 AM
Bash put script jnusa Programming 3 09-07-2004 03:31 AM
Changing Text Size/Terminal Width in Bash TastyWheat Linux - General 2 11-03-2003 12:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:38 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration