This line prepends two backslashes to the first argument to the script. The first backslash in each pair escapes the second.
This line takes the result of the previous one and appends the result of replacing each of the slashes in the second argument with two backslashes.
echo $node`echo $2|sed 's/\//\\\\/g'`
If you were to call your script like this:
scriptname abc /def/ghi/jkl
$node would be "\\abc" and the following would be echoed:
$2 are referred to as positional parameters and represent the first and second arguments to your script. If you wanted to refer to all of them together regardless of how many (up to the limit that your system permits), you would use
Here is a better way to write those two lines:
By using single quotes around the backslashes, you don't need to escape them. Using double quotes around the positional parameter allows it to be expanded.
echo $node$(echo $2 | sed 's|/|\\\\|g')
$() instead of backticks is more readable, they can easily be nested and quoting and escaping are simplified. By using an alternate delimiter (in this case the pipe symbol) with
sed you don't need to escape the slash and the whole thing is more readable. The backslashes still need to be escaped in this case since
sed is processing them rather than Bash.
If you're not familiar with
$() (or backticks) they perform command substitution which means that the output of the enclosed command(s) is substituted in their place.
You may not be familiar with
sed. It is a utility that is external to Bash (or other shells) which can take a Stream of characters and EDit them. The particular command in use here is
s which stands for substitute. It will substitute what's found between the second and third delimiters (usually slashes, but you can use almost any character) for the pattern between the first and second delimiters. The
g is a modifier that causes the substitution to be made globally (i.e. each time it occurs in the input line). The process is repeated for each line of input. In your example there's only one line of input - the output of the echo.