Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hello I am trying to replace a string with another string.

This is my sample

$SITE has been already declared

PARAM="$SITE,90,1000"
PARAM=${PARAM//'$SITE'/$SITE}

but I am getting this error

PARAMS="${PARAMS//"\$SITE"/$SITE}": 0403-011 The specified substitution is not valid for this command.

What is causing this "\ to show up in unix execution?

It works when I do it straight from Shell script.

But these parameters are taken from a text file where I build the PARAM variables. In the end i do an sqlplus statment where i exec procedure(parameters,...);

what is the issue in this scenario?

share|improve this question
    
What is value of $SITE? –  anubhava Apr 15 at 17:16
    
$SITE is a number –  Alkey29 Apr 15 at 17:17
1  
set -vx to see how the shell is executing each line. The '$SITE' that you use in PARAM=... is the equivalent of "\$SITE" displayed in the error msg. As SITE is already declared, try PARAM=${PARAM//"$SITE"/$SITE}. Good luck. –  shellter Apr 15 at 17:21
    
ok ad what is your expected output for PARAM? –  anubhava Apr 15 at 17:22
    
PARAMS is $SITE,90,1000 but since sqlplus is reading it as $SITE, i want to use the replace method to replace the literal site with the value $SITE has been passed. So i want params to end up like 12,90,1000 –  Alkey29 Apr 15 at 17:24

2 Answers 2

How about this instead?

PARAM=$SITE${PARAM#\$SITE}

Removes the literal string $SITE from the beginning of $PARAM, then prepends the actual value of $SITE.

> SITE=12
> PARAM='$SITE,90,1000'
> echo $PARAM 
$SITE,90,1000
> echo "$SITE${PARAM#\$SITE}"
12,90,1000
share|improve this answer

What version of ksh do you have?

$ SITE=42
$ PARAM='$SITE,90,1000'
$ echo ${PARAM//\$SITE/$SITE}
42,90,1000
$ echo ${PARAM//'$SITE'/$SITE}
42,90,1000
$ ksh --version
  version         sh (AT&T Research) 93u 2011-02-08
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.