LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 04-29-2011, 10:45 AM   #1
BMan8577
Member
 
Registered: Apr 2011
Posts: 73

Rep: Reputation: 0
Question How can you create aliases with echoing text into the variable?


For example if you want to create an alias in Linux with a message echoed into the variable would the following command be; alias hello="(echo)"Hello." "? I'm trying to learn some environment variables and aliases.
 
Old 04-29-2011, 11:25 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
It is not really clear what you would hope to gain with what I think it is you are trying to do??
But to do what you ask:
Code:
alias hello='echo Hello'
Now when you type hello at the command prompt it will echo the word Hello, though not particularly useful in itself.
Normally aliases are used to help speed things up or perform a task with a single word, eg:
Code:
alias ll='ls -l'
alias df='df -h'
The first is to reduce the amount of typing but allow the original command to stay the same, namely ls.
The second you might perform if you decide you would always like to have the human readable form shown whenever you use the df command.
 
Old 04-29-2011, 12:24 PM   #3
BMan8577
Member
 
Registered: Apr 2011
Posts: 73

Original Poster
Rep: Reputation: 0
Is there a way I can place my created alias into a file such as: alias Hello > alias.hello? Would that be the command to place that into a file?

---------- Post added 04-29-11 at 01:24 PM ----------

Or would the correct command be: alias Hello='echo Hello' > alias.hello?
 
Old 04-29-2011, 12:38 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
The correct file to put your aliases into would be the configuration file of your shell. I think in most cases this should be ~/.bashrc.
Either edit it with the text-editor of your choice or add it with the echo command.
In any case make a backup of that file first.
The correct command to add an alias to your config file would be:
Code:
echo "alias hello = 'echo hello'" >> ~/.bashrc
Note that you have to use >>, not > for redirection, or you will delete the previous content of your ~/.bashrc.
 
Old 04-29-2011, 01:00 PM   #5
BMan8577
Member
 
Registered: Apr 2011
Posts: 73

Original Poster
Rep: Reputation: 0
Thanks I really appreciate it my credit goes to your successful answers. It worked thanks.
 
  


Reply



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
bash text to variable accessing individual text lines patolfo Programming 11 05-11-2010 10:21 AM
Cannot read text from text file and store it in a variable using shell script anurupr Linux - Newbie 2 03-03-2010 01:38 PM
How to get variable from text file into Bash variable mcdef Linux - Software 2 06-10-2009 01:15 PM
[SOLVED] create command aliases for a user vikas027 Solaris / OpenSolaris 3 05-18-2008 04:26 AM
How to create aliases in MySQL? JockVSJock Linux - Software 1 02-26-2006 12:13 PM

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

All times are GMT -5. The time now is 03:25 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