Link to home
Create AccountLog in
Avatar of Neapolitan23
Neapolitan23

asked on

How To Append Text to Variable & SED

I want to add ' in front and behind my variable and replace one character inside.

Here is my input: peter:chris
Here is my expected output: 'peter-chris'

I have tried, but my code is failing. My echo prints nothing. Code attempt attached.

Appreciate your help.

if [ -n "$string" ]
then
	set string = `echo "'"$string"'" | sed "s/:/-/"`
	echo $string;
fi

Open in new window

Avatar of ozo
ozo
Flag of United States of America image

Which shell are you using, and how did you set $string before running that code?
Avatar of Neapolitan23
Neapolitan23

ASKER

bash shell.

string="$1" (value from the command line)
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account