Sponsored Content
Full Discussion: Single quote _error_.
Top Forums Shell Programming and Scripting Single quote _error_. Post 303027734 by Don Cragun on Saturday 22nd of December 2018 03:19:55 PM
Old 12-22-2018
Expanding on what RudiC has already said and replying to wisecracker's comment that this question is in my domain... If you're trying to write portable code, DO NOT use echo if you intend to invoke it with a first argument starting with <minus-sign> (-), with -- as an argument, or if any argument contains a <backslash> character (\).

The synopsis for echo in the standards is echo [string...] and the options section for echo in the standards says:
Code:
The echo utility shall not recognize the "--" argument in the manner specified by Guideline 10
of XBD Section 12.2 (on page 216); "--" shall be recognized as a string operand.

Implementations shall not support any options.

And then, unlike the description of any other utility in the standards, the description of the string operand is:
Code:
	string	A string to be written to standard output. If the first operand is -n, or if any of the
		operands contain a <backslash> character, the results are implementation-defined.

XSI		On XSI-conformant systems, if the first operand is -n, it shall be treated as a string,
		not an option. The following character sequences shall be recognized on XSI-conformant
		systems within any of the arguments:

		\a	Write an <alert>.

		\b	Write a <backspace>.

		\c	Suppress the <newline> that otherwise follows the final argument in the
			output. All characters following the '\c' in the arguments shall be
			ignored.

		\f	Write a <form-feed>.

		\n	Write a <newline>.

		\r	Write a <carriage-return>.

		\t	Write a <tab>.

		\v	Write a <vertical-tab>.

		\\	Write a <backslash> character.

		\0num	Write an 8-bit value that is the zero, one, two, or three-digit octal number
			num.

Except for the first paragraph of the above quote, this section is shaded and has an XSI margin tag which means that it applies only on systems that support the standard's XSI option (which means that the system supports all of the optional requirements needed for UNIX brand certification by The Open Group in addition to meeting all of the requirements needed for POSIX certification by the IEEE).

Last edited by Don Cragun; 01-06-2019 at 09:56 AM.. Reason: Fix typos: s/−/-/g
These 3 Users Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing a single quote

Hi there I have a data file like so below 'A/1';'T100002';'T100002';'';'01/05/2004';'31/05/2004';'01/06/2004';'08/06/2004';'1.36';'16';'0.22';'0';'0';'1.58';'0';'0';'0';'0';'0';'0';'clientes\resumen\200405\resumen_T100002_T100002_1.pdf';'';'0001';'S';'20040501';'';'02';'0';'S';'N'... (3 Replies)
Discussion started by: rjsha1
3 Replies

2. Shell Programming and Scripting

single quote

Hi I have a shell script with many lines as below: comment on column dcases.proj_seq_num is dcases_1sq; .... .... I want the above script to be as below: comment on column dcases.proj_seq_num is 'dcases_1sq'; I want to have single quotes like that as above for the entire shell... (2 Replies)
Discussion started by: dreams5617
2 Replies

3. Shell Programming and Scripting

escaping single quote

hi, echo 'abc' will give output abc how can i get output as 'abc' plz help. thanks in advance (3 Replies)
Discussion started by: javeed7
3 Replies

4. UNIX for Dummies Questions & Answers

how to print single quote in awk

Hi all, It is a very stupid problem but I am not able to find a solution to it. I am using awk to get a column from a file and I want to get the output field in between single quotes. For example, Input.txt 123 abc 321 ddff 433 dfg ........ I want output file to be as ... (6 Replies)
Discussion started by: gauravgoel
6 Replies

5. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

6. Shell Programming and Scripting

Replace single quote with two single quotes in perl

Hi I want to replace single quote with two single quotes in a perl string. If the string is <It's Simpson's book> It should become <It''s Simpson''s book> (3 Replies)
Discussion started by: DushyantG
3 Replies

7. Shell Programming and Scripting

single quote replacement

hi all, i have a data in the file which of the formate : 100,102,103 and the required formate is \'100\',\'102\',\'103 Idealy we need to replace , with \',\' Regards arkesh (2 Replies)
Discussion started by: arkeshtk
2 Replies

8. Shell Programming and Scripting

How to insert a single quote to each record

I have a file as: 1 New used 1 used New I need o/p as: '1' 'New' 'used' '1' 'used' 'New' (12 Replies)
Discussion started by: karumudi7
12 Replies

9. UNIX for Dummies Questions & Answers

Insert single quote and commas

Hi All, I have a set of data as below : XS012371378 Raj 23-09-12 SH128238948 Andrew 24-08-12 CH273712399 Walsh 12-10-12 JK7249923893 Nick 10-02-13 JP6383791389 Braslin 30-12-13 I want the first column to be extracted separately. I can get this using awk. awk '{print $1}' file_name ... (3 Replies)
Discussion started by: Nand Kishor
3 Replies

10. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies
All times are GMT -4. The time now is 07:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy