Sponsored Content
Operating Systems OS X (Apple) Help in explaining this echo conundrum. Post 302993799 by Corona688 on Tuesday 14th of March 2017 01:46:56 PM
Old 03-14-2017
'echo' is not consistent or portable between different shells. Sometimes you get newlines, sometimes you get \n, sometimes you only get newlines when you ask for them with echo -e, and sometimes you can't get newlines out no matter what you do (i.e. /bin/sh on solaris). Given OSX's nextstep/mach lineage, I'll wild-guess that their /bin/sh is meant to resemble an old Bourne from BSD.

printf is a lot more consistent.
This User Gave Thanks to Corona688 For This Post:
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

explaining awk

i am new to awk scripting. i couldn't figure out how this awk script works can anyone explain? #!/bin/awk -f { for( x=1; x<=NF; ++x) { if( x == 3 ) { continue } print x, $x } } thank you and regards (1 Reply)
Discussion started by: phone_book
1 Replies

2. UNIX for Dummies Questions & Answers

Need help explaining how to use a VPN on a UNIX server with a Mac OS

I have gotten a gig to teach someone how to use a VPN client for a UNIX server on a MAC os. The problem is I have never used UNIX, dont mess with VPN's (my dad has a VPN that I have used a couple of times). I'm currently taking a crash course on UNIX but I was wondering if anyone could help me with... (0 Replies)
Discussion started by: psycopuppy
0 Replies

3. UNIX for Dummies Questions & Answers

Explaining some lines from files : .login and .cshrc

Hello, can anyone explain me please what do those lines do ? From file .login 1) set history=40 2) setenv MACH `uname -s` 3) source /etc/login 4) source ~/$MACH/.login From file .cshrc 1) if ( ! $?prompt) exit 0 (5 Replies)
Discussion started by: bbqtoss
5 Replies

4. UNIX for Dummies Questions & Answers

umask conundrum

Hi All, i was reading up on a umask question on this forum and have a question on this. the umask value on my home PC running on cygwin is 022. when i create a dir it defaults to permission 755, when i create a file it defaults to 644. Now it starts at 777 for dirs and 666 for files and... (1 Reply)
Discussion started by: Irishboy24
1 Replies

5. Shell Programming and Scripting

Conundrum - Flexible way to strip extension

Hi, First post here. I have something that may prove to be difficult. I have the following files: Example1.0.0.tar.gz Example2.tar Example3.zip Example4.0.0.0.0.0.bzip2 I need to remove the file extensions and store as a variable so they look like this: Example1.0.0 Example2... (3 Replies)
Discussion started by: Spadez
3 Replies

6. Shell Programming and Scripting

sudo scripts conundrum

hello; Got a problem running monitoring scripts using sudo ssh.. Mgmt decided to take away root sudoers access.. so most of the scripts ran as: sudo ssh $BOX ... Now I need to run them as: echo $my_pw | sudo -S -l my_user_id $BOX ... I tried this but not working.. Any wisdom/tricks... (3 Replies)
Discussion started by: delphys
3 Replies

7. Shell Programming and Scripting

Help to explaining a command in run dot tcl

Hi, I'm running a rdt (run dot tcl) command, and come accross this line: alias abc 'set ARGS =(\!*); source home123/abc/$ARGS/setup' What does the command exactly do? Please help. (6 Replies)
Discussion started by: mar85
6 Replies

8. IP Networking

iptables conundrum

Ok, if youre reading this prepare yourself.(debian based os) so im trying to do this routing with ip tables, i need to forward/SNAT traffic from 192.168.111.1 to 10.10.10.250, the 192.x.x.x ips are being shoved into a honeyd like program called inetsim so its offline, 10.10.10.125 is connected... (3 Replies)
Discussion started by: Shocco
3 Replies
echo(1) 							   User Commands							   echo(1)

NAME
echo - echo arguments SYNOPSIS
/usr/bin/echo [string...] DESCRIPTION
The echo utility writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. If there are no arguments, only the NEWLINE character will be written. echo is useful for producing diagnostics in command files, for sending known data into a pipe, and for displaying the contents of environ- ment variables. The C shell, the Korn shell, and the Bourne shell all have echo built-in commands, which, by default, will be invoked if the user calls echo without a full pathname. See shell_builtins(1). sh's echo, ksh's echo, and /usr/bin/echo understand the back-slashed escape charac- ters, except that sh's echo does not understand a as the alert character. In addition, ksh's echo, does not have an -n option. sh's echo and /usr/bin/echo only have an -n option if the SYSV3 environment variable is set (see ENVIRONMENT VARIABLES below). If it is, none of the backslashed characters mentioned above are available. csh's echo and /usr/ucb/echo, on the other hand, have an -n option, but do not under- stand the back-slashed escape characters. OPERANDS
The following operand is supported: string A string to be written to standard output. If any operand is "-n", it will be treated as a string, not an option. The following character sequences will be recognized within any of the arguments: a Alert character.  Backspace. c Print line without new-line. All characters following the c in the argument are ignored. f Form-feed. New-line. Carriage return. Tab. v Vertical tab. \ Backslash. n Where n is the 8-bit character whose ASCII code is the 1-, 2- or 3-digit octal number representing that character. USAGE
Portable applications should not use -n (as the first argument) or escape sequences. The printf(1) utility can be used portably to emulate any of the traditional behaviors of the echo utility as follows: o The Solaris 2.6 operating environment or compatible version's /usr/bin/echo is equivalent to: printf "%b " "$*" o The /usr/ucb/echo is equivalent to: if [ "X$1" = "X-n" ] then shift printf "%s" "$*" else printf "%s " "$*" fi New applications are encouraged to use printf instead of echo. EXAMPLES
Example 1: Finding how far below root your current directory is located 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 $PWD | tr '/' ' ' | wc -w See tr(1) and wc(1) for their functionality. Below are the different flavors for echoing a string without a NEWLINE: Example 2: /usr/bin/echo example% /usr/bin/echo "$USER's current directory is $PWDc" Example 3: sh/ksh shells example$ echo "$USER's current directory is $PWDc" Example 4: csh shell example% echo -n "$USER's current directory is $PWD" Example 5: /usr/ucb/echo example% /usr/ucb/echo -n "$USER's current directory is $PWD" ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of echo: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. SYSV3 This environment variable is used to provide compatibility with INTERACTIVE UNIX System and SCO UNIX installation scripts. It is intended for compatibility only and should not be used in new scripts. EXIT STATUS
The following error values are returned: 0 Successful completion. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
echo(1B), printf(1), shell_builtins(1), tr(1), wc(1), ascii(5), attributes(5), environ(5), standards(5) NOTES
When representing an 8-bit character by using the escape convention n, the n must always be preceded by the digit zero(0). For example, typing: echo 'WARNING:7' will print the phrase WARNING: and sound the "bell" on your terminal. The use of single (or double) quotes (or two backslashes) is required to protect the "" that precedes the "07". Following the , up to three digits are used in constructing the octal output character. If, following the n, you want to echo addi- tional digits that are not part of the octal representation, you must use the full 3-digit n. For example, if you want to echo "ESC 7" you must use the three digits "033" rather than just the two digits "33" after the . 2 digits Incorrect: echo"0337 | od -xc produces: df0a (hex) 337 (ascii) 3 digits Correct: echo "00337" | od -xc produces: lb37 0a00 (hex) 033 7 (ascii) For the octal equivalents of each character, see ascii(5). SunOS 5.10 20 Jan 2000 echo(1)
All times are GMT -4. The time now is 09:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy