Sponsored Content
Operating Systems OS X (Apple) Help in explaining this echo conundrum. Post 302993810 by wisecracker on Tuesday 14th of March 2017 03:39:45 PM
Old 03-14-2017
@ Scrutinizer...

Also interestingly when using 'dash' on OSX 10.12.3 default bash terminal:-
Code:
Last login: Tue Mar 14 18:32:20 on ttys000
AMIGA:amiga~> /usr/local/bin/dash
AMIGA:\u\w> echo '1\n2\n3\n4\n5' > /tmp/text
AMIGA:\u\w> hexdump -C /tmp/text
00000000  31 0a 32 0a 33 0a 34 0a  35 0a                    |1.2.3.4.5.|
0000000a
AMIGA:\u\w> /bin/echo '1\n2\n3\n4\n5' > /tmp/text
AMIGA:\u\w> hexdump -C /tmp/text
00000000  31 5c 6e 32 5c 6e 33 5c  6e 34 5c 6e 35 0a        |1\n2\n3\n4\n5.|
0000000e
AMIGA:\u\w> exit
AMIGA:amiga~> _

Seems consistent with 'sh'.
I am going to have to be careful with this.

---------- Post updated at 07:39 PM ---------- Previous update was at 07:10 PM ----------

Quote:
Originally Posted by Corona688
'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.
I do know a few ideas but do not know if this would work in the Solaris situation you quoted.
This is longhand using 'dash' and '/bin/echo'...
You will have to take my word for the 'bold' as it does not copy and paste too well... ;o)
Code:
Last login: Tue Mar 14 19:22:37 on ttys000
AMIGA:amiga~> /usr/local/bin/dash
AMIGA:\u\w> nl='
> '
AMIGA:\u\w> esc=`printf "\033"`
AMIGA:\u\w> /bin/echo '1\n2\n3'
1\n2\n3
AMIGA:\u\w> /bin/echo "1\n2\n3"
1\n2\n3
AMIGA:\u\w> /bin/echo '1${nl}2${nl}3'
1${nl}2${nl}3
AMIGA:\u\w> /bin/echo "1${nl}2${nl}3"
1
2
3
AMIGA:\u\w> # Make characters BOLD...
AMIGA:\u\w> /bin/echo "Normal text, $esc[1mbold text..."
Normal text, bold text...
AMIGA:\u\w> exit
AMIGA:amiga~> _

There are ways to bend rules even in dash...

Last edited by wisecracker; 03-14-2017 at 04:43 PM.. Reason: Sorry about the attachment. I did expect a new window.
 

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
LIBBASH(7)							  libbash Manual							LIBBASH(7)

NAME
libbash -- A bash shared libraries package. DESCRIPTION
libbash is a package that enables bash dynamic-like shared libraries. Actually its a tool for managing bash scripts whose functions you may want to load and use in scripts of your own. It contains a 'dynamic loader' for the shared libraries ( ldbash(1)), a configuration tool (ldbashconfig(8)), and some libraries. Using ldbash(1) you are able to load loadable bash libraries, such as getopts(1) and hashstash(1). A bash shared library that can be loaded using ldbash(1) must answer 4 requirments: 1. It must be installed in $LIBBASH_PREFIX/lib/bash (default is /usr/lib/bash). 2. It must contain a line that begins with '#EXPORT='. That line will contain (after the '=') a list of functions that the library exports. I.e. all the function that will be usable after loading that library will be listed in that line. 3. It must contain a line that begins with '#REQUIRE='. That line will contain (after the '=') a list of bash libraries that are required for our library. I.e. every bash library that is in use in our bash library must be listed there. 4. The library must be listed (For more information, see ldbashconfig(8)). Basic guidelines for writing library of your own: 1. Be aware, that your library will be actually sourced. So, basically, it should contain (i.e define) only functions. 2. Try to declare all variables intended for internal use as local. 3. Global variables and functions that are intended for internal use (i.e are not defined in '#EXPORT=') should begin with: __<library_name>_ For example, internal function myfoosort of hashstash library should be named as __hashstash_myfoosort This helps to avoid conflicts in global name space when using libraries that come from different vendors. 4. See html manual for full version of this guide. AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <ril@ran4.net> SEE ALSO
ldbash(1), ldbashconfig(8), getopts(1), hashstash(1) colors(1) messages(1) urlcoding(1) locks(1) Linux Epoch Linux
All times are GMT -4. The time now is 10:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy