Skip to main content
added 308 characters in body
Source Link
Olivier Dulac
  • 6.6k
  • 1
  • 26
  • 42

new answer: read -r var

-r raw input - disables interpretion of backslash escapes and line-continuation in the read data 

and to display:

printf "%s" "$var" echo "$var" 

should work.

So for your foo function:

function foo { read -r var echo -E "var is : ${var}" } $ foo \\here\is\some\path var is : \\here\is\some\path 

old answer below (not answering, but maybe usefull ^^)

just replace each \ by \\ to tell the shell "that it a literall \ I want". otherwise (for example in zsh, in your example) it could well be that \b means "1 backspace", or whatever.

you could for example use sed:

sed -e 's,\\,\\\\,g' < the_original > the_escaped_backslaches_version 

(see how you also need to escape "" there, to tell sed the same thing: "it is a literall "" I want) (and notice I surround it by ' ' and not " " to avoid the shell to interpret most of it too)

new answer: read -r

-r raw input - disables interpretion of backslash escapes and line-continuation in the read data 

old answer below (not answering, but maybe usefull ^^)

just replace each \ by \\ to tell the shell "that it a literall \ I want". otherwise (for example in zsh, in your example) it could well be that \b means "1 backspace", or whatever.

you could for example use sed:

sed -e 's,\\,\\\\,g' < the_original > the_escaped_backslaches_version 

(see how you also need to escape "" there, to tell sed the same thing: "it is a literall "" I want) (and notice I surround it by ' ' and not " " to avoid the shell to interpret most of it too)

new answer: read -r var

-r raw input - disables interpretion of backslash escapes and line-continuation in the read data 

and to display:

printf "%s" "$var" echo "$var" 

should work.

So for your foo function:

function foo { read -r var echo -E "var is : ${var}" } $ foo \\here\is\some\path var is : \\here\is\some\path 

old answer below (not answering, but maybe usefull ^^)

just replace each \ by \\ to tell the shell "that it a literall \ I want". otherwise (for example in zsh, in your example) it could well be that \b means "1 backspace", or whatever.

you could for example use sed:

sed -e 's,\\,\\\\,g' < the_original > the_escaped_backslaches_version 

(see how you also need to escape "" there, to tell sed the same thing: "it is a literall "" I want) (and notice I surround it by ' ' and not " " to avoid the shell to interpret most of it too)

added 308 characters in body
Source Link
Olivier Dulac
  • 6.6k
  • 1
  • 26
  • 42

new answer: read -r

-r raw input - disables interpretion of backslash escapes and line-continuation in the read data 

old answer below (not answering, but maybe usefull ^^)

just replace each ""\ by "\\"\\ to tell the shell "that it a literall ''\ I want". otherwise (for example in zsh, in your example) it could well be that "\b"\b means "1 backspace", or whatever.

you could for example use sed:

sed -e 's,\\,\\\\,g' < the_original > the_escaped_backslaches_version 

(see how you also need to escape "" there, to tell sed the same thing: "it is a literall "" I want) (and notice I surround it by ' ' and not " " to avoid the shell to interpret most of it too)

just replace each "" by "\\" to tell the shell "that it a literall '' I want". otherwise (for example in zsh, in your example) it could well be that "\b" means "1 backspace", or whatever.

new answer: read -r

-r raw input - disables interpretion of backslash escapes and line-continuation in the read data 

old answer below (not answering, but maybe usefull ^^)

just replace each \ by \\ to tell the shell "that it a literall \ I want". otherwise (for example in zsh, in your example) it could well be that \b means "1 backspace", or whatever.

you could for example use sed:

sed -e 's,\\,\\\\,g' < the_original > the_escaped_backslaches_version 

(see how you also need to escape "" there, to tell sed the same thing: "it is a literall "" I want) (and notice I surround it by ' ' and not " " to avoid the shell to interpret most of it too)

SO escapes backslashes too :)
Source Link
peterph
  • 31.5k
  • 3
  • 74
  • 76

just replace each \"" by \\"\\" to tell the shell "that it a literall \'' I want". otherwise (for example in zsh, in your example) it could well be that \b"\b" means "1 backspace", or whatever.

just replace each \ by \\ to tell the shell "that it a literall \ I want". otherwise (for example in zsh, in your example) it could well be that \b means "1 backspace", or whatever.

just replace each "" by "\\" to tell the shell "that it a literall '' I want". otherwise (for example in zsh, in your example) it could well be that "\b" means "1 backspace", or whatever.

Source Link
Olivier Dulac
  • 6.6k
  • 1
  • 26
  • 42
Loading