Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Difference between echo `ls -l` and echo "`ls -l`" ? Post 302912076 by sreyan32 on Tuesday 5th of August 2014 02:48:34 PM
Old 08-05-2014
Difference between echo `ls -l` and echo "`ls -l`" ?

Hi guys,
Been messing around with shell programming for a couple of days and I found something that was pretty odd in the behavior of the echo command. Below is an example-:

When I type the following in my /home directory from my lxterminal in Debian-:

echo "`ls -l`"

I get the following output-:
Code:
sreyan@debian:~$ echo "`ls -l`"
total 2296148
drwx------ 4 sreyan sreyan       4096 Jul 31 15:21 Desktop
-rw------- 1 sreyan sreyan     102097 Dec 26  2009 Euphoria.jpg
drwx------ 3 sreyan sreyan       4096 Feb 10 21:28 GNUstep
-rw------- 1 sreyan sreyan 1239269270 Aug 21  2009 linux.x64_11gR2_database_1of2.zip
-rw------- 1 sreyan sreyan 1111416131 Aug 21  2009 linux.x64_11gR2_database_2of2.zip
-rw-r--r-- 1 sreyan sreyan     447144 Jul 24 18:34 RedshiftGUI-0.2.1-Linux-x86_64.deb

Now this is what I expected. I know whatever is put in ` ` is suppose to interpreted as a command in the BASH echo. So, therefore this is the expected output of ls -l on my /home directory.

But it gets weird when I remove the " " (double quotes) from the echo statement.

When I run the following-:

echo `ls -l`

I get as output the following-:
Code:
total 2296148 drwx------ 4 sreyan sreyan 4096 Jul 31 15:21 Desktop -rw------- 1 sreyan sreyan 102097 Dec 26 2009 Euphoria.jpg drwx------ 3 sreyan sreyan 4096 Feb 10 21:28 GNUstep -rw------- 1 sreyan sreyan 1239269270 Aug 21 2009 linux.x64_11gR2_database_1of2.zip -rw------- 1 sreyan sreyan 1111416131 Aug 21 2009 linux.x64_11gR2_database_2of2.zip -rw-r--r-- 1 sreyan sreyan 447144 Jul 24 18:34 RedshiftGUI-0.2.1-Linux-x86_64.deb

If you look closely you will see that it is exactly identical to the output that is given above except for the fact that it contains no line breaks. My question is why ?

  1. Why are the line-breaks removed when I remove the double quotes from echo ? Whatever is there in ` `(tild signs) is supposed to be interpreted as a command right ?
  2. If removal of double quotes " " means that there is a change in the meaning of the echo, then please tell me what is the special meaning that double quotes has in echo ?
  3. Is there any difference between echo "$SHELL" and echo $SHELL ? I know the output is same but since one has double quotes and one doesn't is there any difference in the way that BASH treats them internally ?
I am using Debian Wheezy LXDE with Bash 4.2.
Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

difference between echo and ""

hi guys wht is the difference between these two command in bash shell scripting $var1=world! $echo hello $var1 $echo "hello $var1" (8 Replies)
Discussion started by: srinivas2828
8 Replies

2. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

3. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

4. Shell Programming and Scripting

ksh script that echo " please insert your name " and store the output to a login.log file.

Hello All Nice to meet you all here in this forum, it's my 1rst time here i'm asking about a little issue that i face i added a ksh script that echo " please insert your name " and store the output to a login.log file. the script is working fine with normal telnet but Xstart is not working... (8 Replies)
Discussion started by: islam.said
8 Replies

5. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

6. HP-UX

echo "selall;info;wait;infolog" | /usr/sbin/cstm problem

Hello, On a HP-UX 10.20 server I've executed something similar to this command: # echo 'selall;info;wait;infolog;view;done' | /usr/sbin/cstm But it returns sometype of "argument list too long" error. I suppose there is a way to fix it by using xargs but I can't figure it out. Any... (7 Replies)
Discussion started by: asanchez
7 Replies

7. Shell Programming and Scripting

"Simple" echo/reading variable question...

Hello, I have a simple(I think) question! Although simple, I have been unable to resolve it, so I hope someone can help! OK, here it is: 1)I have an awk script that prints something, such as: awk '{print $2}' a > x so x might hold the value of say '10' 2)Now, I just want to check to see if... (4 Replies)
Discussion started by: astropi
4 Replies

8. Shell Programming and Scripting

cmd || echo "something" - doesn't exit uppon error

Hi guys, I have a shell script where I have the following: for i in ad0 ad1 do gpart create -s gpt $i || echo "Cannot create GPT partition on "$i". Exiting ..." gpart add -s 128 -t freebsd-boot $i || echo "Cannot add freebsd-boot partition on "$i". Exiting ..." gpart add -s 4G -t... (2 Replies)
Discussion started by: da1
2 Replies

9. AIX

echo $varibla | mail -s "subject" "xxx@xxx.com" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "xxx@xxx.com" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

10. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies
ECHO(1) 							   User Commands							   ECHO(1)

NAME
echo - display a line of text SYNOPSIS
echo [SHORT-OPTION]... [STRING]... echo LONG-OPTION DESCRIPTION
Echo the STRING(s) to standard output. -n do not output the trailing newline -e enable interpretation of backslash escapes -E disable interpretation of backslash escapes (default) --help display this help and exit --version output version information and exit If -e is in effect, the following sequences are recognized: NNN the character whose ASCII code is NNN (octal) \ backslash a alert (BEL)  backspace c produce no further output f form feed new line carriage return horizontal tab v vertical tab NOTE: your shell may have its own version of echo, which usually supersedes the version described here. Please refer to your shell's docu- mentation for details about the options it supports. AUTHOR
Written by Brian Fox and Chet Ramey. REPORTING BUGS
Report echo bugs to bug-coreutils@gnu.org GNU coreutils home page: <http://www.gnu.org/software/coreutils/> General help using GNU software: <http://www.gnu.org/gethelp/> COPYRIGHT
Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
The full documentation for echo is maintained as a Texinfo manual. If the info and echo programs are properly installed at your site, the command info coreutils 'echo invocation' should give you access to the complete manual. GNU coreutils 7.1 July 2010 ECHO(1)
All times are GMT -4. The time now is 07:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy