Shell Script -- problem reading backslash(\)!!

Hello! I am writing a program that reads a bunch of arguments from the command line,then read information from a file(passed as one of the arguments) and do some computation. The problem I am facing is when a backslash(\) is present as one of the arguments, suppose $ myprog \ abc xyz,the backslash is completely ignored, for the previous example $1 is "abc" where as it should be "\", I have tried using double-quotes("$1") but it still stays the same. The problem is the same when I am reading from a file the backslash character is completely ignored as if it were a space or a tab.
How can I prevent htis and read "\" as it is? Your help will be greatly appreciated.

either use two, or use single quote:

$ set -- \\ abc
$ echo $1
\
$ set -- '\' abc
$ echo $1
\

Use the -r option:

read -r VAR
1 Like