Sponsored Content
Top Forums Shell Programming and Scripting Special characters in command arguments Post 302603972 by Corona688 on Friday 2nd of March 2012 12:45:31 PM
Old 03-02-2012
You are attempting to put single quotes inside single quotes, which just doesn't work, because single quotes don't let you escape anything. Try double quotes.

Code:
"s/'/\\'/g"

I'm not positive that's what you want however -- you showed the output you don't want, but not any output you do want, just a regex which didn't do what you want...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies

2. Shell Programming and Scripting

Special characters

When I open a file in vi, I see the following characters: \302\240 Can someone explain what these characters mean. Is it ASCII format? I need to trim those characters from a file. I am doing the following: tr -d '\302\240' ---------- Post updated at 08:35 PM ---------- Previous... (1 Reply)
Discussion started by: sid1982
1 Replies

3. UNIX for Dummies Questions & Answers

How to see special characters?

Hi all, I was wondering how can i see the special characters like \t, \n or anything else in a file by using Nano or any other linux command like less, more etc (6 Replies)
Discussion started by: gvj
6 Replies

4. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

5. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

6. Shell Programming and Scripting

Need help in replacing special characters

I am writing a ksh script. I need to replace a set of characters in an xml file. FROM="ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÛÚÜÝßàáâãäåçèéêëìíîïðñòóôõö¿¶ø®"; TO="AAAAAAACEEEEIIIIDNOOOOOOUUUUYSaaaaaaceeeeiiiionooooo N R" I have used the code- sed 's/$FROM/$TO/g'<abc.xml But its not working. Can anyone tell me the code to do this? (3 Replies)
Discussion started by: saga20
3 Replies

7. Shell Programming and Scripting

A test command parameter is not valid, when special characters are tried to match

Hi I have a scenario where hyphen(-) from file should be ignored I used the following code if && ; then if ; then pow=$LINE echo $pow > history.txt flag=1 fi fi I get the following output ./valid.sh: -: 0403-012 A test... (7 Replies)
Discussion started by: Priya Amaresh
7 Replies

8. Shell Programming and Scripting

How to escape all special characters?

I have an application which I am integrating with that accepts the password via a CLI. I am running in to issues with passwords that contain special characters. I tried to escape them all, but I ran in to an issue where I cannot escape the characters ' ] My attempt is as follows: $... (2 Replies)
Discussion started by: AMG1978
2 Replies

9. Shell Programming and Scripting

Tcsh script - sed command for special characters

Hi, I am using sed command to replace following line in gz file- sed -n 's/""COS_12_TM_1" ( 1101110101001001010011110100000010110100010010000000100000000010XX010000000 )"/""COS_12_TM_1" ( 110111010100100101001111MM00000010110100010010000000100000000010XX010000000 )"/g' filename.gz $x=... (4 Replies)
Discussion started by: Preeti Chandra
4 Replies

10. Shell Programming and Scripting

Using CURL command with special characters in URL

Hi. I 'm trying to hit a REST api and retrieve a JSON feed, and the URL has special characters in it. Something like: Example Domain The below curl command is failing curl -X GET https://www.example.com/?sample=name&id=1001 saying bad command at id=1001 I am going to use this as part... (3 Replies)
Discussion started by: kumarjt
3 Replies
SHQUOTE(3)						   BSD Library Functions Manual 						SHQUOTE(3)

NAME
shquote, shquotev -- quote argument strings for use with the shell LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdlib.h> size_t shquote(const char *arg, char *buf, size_t bufsize); size_t shquotev(int argc, char * const *argv, char *buf, size_t bufsize); DESCRIPTION
The shquote() and shquotev() functions copy strings and transform the copies by adding shell escape and quoting characters. They are used to encapsulate arguments to be included in command strings passed to the system() and popen() functions, so that the arguments will have the correct values after being evaluated by the shell. The exact method of quoting and escaping may vary, and is intended to match the conventions of the shell used by system() and popen(). It may not match the conventions used by other shells. In this implementation, the following transformation is applied to each input string: o it is surrounded by single quotes ('), o any single quotes in the input are escaped by replacing them with the four-character sequence: ''', and o extraneous pairs of single quotes (caused by multiple adjacent single quotes in the input string, or by single quotes at the begin- ning or end of the input string) are elided. The shquote() function transforms the string specified by its arg argument, and places the result into the memory pointed to by buf. The shquotev() function transforms each of the argc strings specified by the array argv independently. The transformed strings are placed in the memory pointed to by buf, separated by spaces. It does not modify the pointer array specified by argv or the strings pointed to by the pointers in the array. Both functions write up to bufsize - 1 characters of output into the buffer pointed to by buf, then add a NUL character to terminate the out- put string. If bufsize is given as zero, the buf parameter is ignored and no output is written. RETURN VALUES
The shquote() and shquotev() functions return the number of characters necessary to hold the result from operating on their input strings, not including the terminating NUL. That is, they return the length of the string that would have been written to the output buffer, if it were large enough. If an error occurs during processing, the value ((size_t)-1) is returned and errno is set appropriately. EXAMPLES
The following code fragment demonstrates how you might use shquotev() to construct a command string to be used with system(). The command uses an environment variable (which will be expanded by the shell) to determine the actual program to run. Note that the environment vari- able may be expanded by the shell into multiple words. The first word of the expansion will be used by the shell as the name of the program to run, and the rest will be passed as arguments to the program. char **argv, c, *cmd; size_t cmdlen, len, qlen; int argc; ... /* * Size buffer to hold the command string, and allocate it. * Buffer of length one given to snprintf() for portability. */ cmdlen = snprintf(&c, 1, "${PROG-%s} ", PROG_DEFAULT); qlen = shquotev(argc, argv, NULL, 0); if (qlen == (size_t)-1) { ... } cmdlen += qlen + 1; cmd = malloc(cmdlen); if (cmd == NULL) { ... } /* Create the command string. */ len = snprintf(cmd, cmdlen, "${PROG-%s} ", PROG_DEFAULT); qlen = shquotev(argc, argv, cmd + len, cmdlen - len); if (qlen == (size_t)-1) { /* Should not ever happen. */ ... } len += qlen; /* "cmd" can now be passed to system(). */ The following example shows how you would implement the same functionality using the shquote() function directly. char **argv, c, *cmd; size_t cmdlen, len, qlen; int argc, i; ... /* * Size buffer to hold the command string, and allocate it. * Buffer of length one given to snprintf() for portability. */ cmdlen = snprintf(&c, 1, "${PROG-%s} ", PROG_DEFAULT); for (i = 0; i < argc; i++) { qlen = shquote(argv[i], NULL, 0); if (qlen == (size_t)-1) { ... } cmdlen += qlen + 1; } cmd = malloc(cmdlen); if (cmd == NULL) { ... } /* Start the command string with the env var reference. */ len = snprintf(cmd, cmdlen, "${PROG-%s} ", PROG_DEFAULT); /* Quote all of the arguments when copying them. */ for (i = 0; i < argc; i++) { qlen = shquote(argv[i], cmd + len, cmdlen - len); if (qlen == (size_t)-1) { /* Should not ever happen. */ ... } len += qlen; cmd[len++] = ' '; } cmd[--len] = ''; /* "cmd" can now be passed to system(). */ SEE ALSO
sh(1), popen(3), system(3) BUGS
This implementation does not currently handle strings containing multibyte characters properly. To address this issue, /bin/sh (the shell used by system() and popen()) must first be fixed to handle multibyte characters. When that has been done, these functions can have multi- byte character support enabled. BSD
September 7, 2008 BSD
All times are GMT -4. The time now is 08:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy