LinuxQuestions.org
Visit Jeremy's Blog.
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 08-14-2017, 01:05 PM   #1
Etcetera_77
LQ Newbie
 
Registered: Jul 2017
Posts: 3

Rep: Reputation: Disabled
using echo in an alias??


How do you use echo in an alias?

/etc/bashrc:

alias aliasname=`echo "Hello"`

bash: Hello: command not found...
 
Old 08-14-2017, 01:17 PM   #2
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,513

Rep: Reputation: 1009Reputation: 1009Reputation: 1009Reputation: 1009Reputation: 1009Reputation: 1009Reputation: 1009Reputation: 1009
Hi Etcetera_77,

Welcome to LQ!

Just switch the quotes: alias name="echo 'hello'"

Last edited by AwesomeMachine; 08-14-2017 at 06:53 PM.
 
Old 08-14-2017, 02:54 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Welcome to LQ!

in a terminal issue
Code:
MESSAGE=LQRocks 
echo "$MESSAGE"
http://tldp.org/LDP/abs/html/aliases.html discusses this very subject.


Hope that helps.
 
Old 08-15-2017, 04:10 AM   #4
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 759

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
To debug what happened in #1, display what your alias aliasname actually is, by:
alias aliasname
You will get: alias aliasname='Hello'
So, your alias is the same as typing the invalid command: Hello

What happened was that you used backquotes, which executed the echo inside them first, then defined aliasname!!!
Maybe you wanted 'regular' 'forward' quotes. See also $(cmd) in bash syntax.
Welcome to the 'secret' world of: the bash topics of quoting and command substitution!!!

You (&I!!!) can use [code]terminal stuff[/code], to make post look nice, like#3. Also, at top, mark thread 'solved' when done here. Let us know.
 
Old 08-15-2017, 04:24 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,655
Blog Entries: 3

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
As mentioned above, it's about the quotes. The backticks are for command substituion and better writter as $( ... ) instead of ` ... ` for reasons that are clear.

Look up a short guide or tutorial on quoting in shell scripts and then experiment a little:

Code:
 
date +%F;
dt='date +%F';
echo  `$dt`;
echo $($dt);
echo  "$dt";
echo  '$dt';
Notice how the different types of quotes are or aren't interpreted by the shell.
 
1 members found this post helpful.
  


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
.bashrc alias echo login string to terminal. How to turn off? Jlove130 Linux - General 13 01-14-2014 09:24 AM
[SOLVED] Sort numbers in ascending order using echo, and as an alias robfraser Linux - Newbie 2 04-18-2012 03:44 PM
grep | xargs -I echo $(foo; bar; echo $(fee; fi; fo; fum)) == questionable output.. GrapefruiTgirl Programming 11 12-07-2010 07:02 PM
What does echo alias "char-major-10-224 off" >> /etc/modules.conf do? abefroman Linux - Software 2 09-16-2009 10:10 PM
ls | echo, I got blank, why can't echo take the 2nd seat in a pipeline? elinuxqs Linux - Newbie 6 11-24-2006 08:25 AM

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

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