Sponsored Content
Top Forums Shell Programming and Scripting Where does the 8 come from? (or what happend to the first `) Post 302296279 by Perderabo on Tuesday 10th of March 2009 05:59:56 PM
Old 03-10-2009
To answer the question, the echo man page says:
Code:
 \0n   where n is the 8-bit character whose ASCII  code
                 is the 1-, 2- or 3-digit octal number represent-
                 ing that character.

So the \0 just says that 1, 2, or 3 digits may follow. That zero in \0 is not counted as of of the digits. So
echo "\047"0
is seen by the echo command exactly like
echo "\0470"
and is interrpreted as an attempt to use a byte with the octal value "470". This is too big and so leading bits are dropped. In this case the bit represented by the 4 is dropped and character becomes "\070".

Code:
# echo "\0470" | od -to1
0000000 070 012
0000002
# bc
obase=2
ibase=8
470
100111000
#

Edit:
By the way, a couple of ways that do work:
Code:
# echo "'0'"
'0'
# echo "\00470\0047"
'0'
#

 

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

its happend after restart.

From Sept 12th onwards i am facing some problem in the file permission. Normally the file get generated by a script with the permission 666 and from sept 12th onwards it get changed to 644 If we create a blank file using touch command it is with the permission 666, but the files which are... (3 Replies)
Discussion started by: onlytorobin
3 Replies

2. Shell Programming and Scripting

What happend?

Hi everybody: Could anybody tell me how I can solve this mistake. I have two files and i would like one, so I use the cat command, like always: cat file1.dat file2.dat > file3.dat But the first line from file2.dat is concatenated with the last line from file1.dat: file1.dat... (2 Replies)
Discussion started by: tonet
2 Replies
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.11 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 05:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy