1831355 Members
3196 Online
110024 Solutions
New Discussion

Shell Scripting

 
SOLVED
Go to solution
Ragni Singh
Super Advisor

Shell Scripting

Hello,
Can someone please explain to me what the hell does this mean. Your help wil be greatly appreciated.

echo $(echo $LINE\~|sed -e s%^%$i~%)\\c

3 REPLIES 3
Mark Greene_1
Honored Contributor
Solution

Re: Shell Scripting

>>echo $(echo $LINE\~|sed -e s%^%$i~%)\\c <<

The first "echo" is going to display the results of what happens in the parenthesis and suppress the carriabe return that normally would happen at the end of that display.

The second "echo" will display (send to standard out, but you won't see it because the pipe "|" will capture it) the contents of the variable LINE plus a ~ appended to the end. The "\" is there to tell the shell to treat the ~ as just another text character.

The "sed" command is going to read the contents of the pipe (which is the results of the second echo) and substitute all occurances of ^ with the content of the variable "i" plus a ~. The "-e" tells sed what comes next is an editing command; the "%" are delimiters for the editing command.

So the net affect is whatever the variable LINE equals before doing the above will be displayed with all carats being swapped for whatever is in variable i plus a tilde, plus a tilde at the end.

Given:

LINE=1^2^3
i=-

the results would be:

1-~2-~3~

HTH
mark
the future will be a lot like now, only later
Ragni Singh
Super Advisor

Re: Shell Scripting

Thank you very much for you help Mark but what does the % sign actully mean. What is that there for??
Mark Greene_1
Honored Contributor

Re: Shell Scripting

the % is a delimiter, a seperator for the sed command and is a required part of the syntax. Ususally a slash (/) is used, but if either the string being replaced, or the replacement string contain a slash, you have to used something else. Almost anything will do except a backslash, asterisk, and maybe a few other special characters.

I must admit this is the first time I've seen a percent sign used, the usual fallback is a dash or a plus from what I've seen. Of course, either the incoming string from LINE or the contents of variable "i" could have anynumber of different characters in them.

HTH
mark
the future will be a lot like now, only later