LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 02: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, 02:17 PM   #2
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Hi Etcetera_77,

Welcome to LQ!

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

Last edited by AwesomeMachine; 08-14-2017 at 07:53 PM.
 
Old 08-14-2017, 03: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, 05:10 AM   #4
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 997

Rep: Reputation: 383Reputation: 383Reputation: 383Reputation: 383
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, 05:24 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,678
Blog Entries: 4

Rep: Reputation: 3927Reputation: 3927Reputation: 3927Reputation: 3927Reputation: 3927Reputation: 3927Reputation: 3927Reputation: 3927Reputation: 3927Reputation: 3927Reputation: 3927
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 10:24 AM
[SOLVED] Sort numbers in ascending order using echo, and as an alias robfraser Linux - Newbie 2 04-18-2012 04:44 PM
grep | xargs -I echo $(foo; bar; echo $(fee; fi; fo; fum)) == questionable output.. GrapefruiTgirl Programming 11 12-07-2010 08:02 PM
What does echo alias "char-major-10-224 off" >> /etc/modules.conf do? abefroman Linux - Software 2 09-16-2009 11: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 09:25 AM

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

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