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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script -- problem reading backslash(\)!!
# 1  
Old 04-01-2007
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.
# 2  
Old 04-01-2007
either use two, or use single quote:

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

# 3  
Old 04-04-2007
Quote:
Originally Posted by rossi143
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.

Use the -r option:
Code:
read -r VAR

This User Gave Thanks to cfajohnson For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print backslash in shell script using awk?

I found that echo "aaa" | awk '{print ",\\";}' works, and it will give "\". but ddd=`echo "aaa" | awk '{print ",\\";}'`; echo $ddd will not work. Could anyone tell me why? thank you. (8 Replies)
Discussion started by: wxuyec
8 Replies

2. Shell Programming and Scripting

[SH] Problem reading input in script

Alright, so the goal of my script is to read text from standard input and store it into a file using the ex-editor: so far i've got this, but it doesn't work. #!/bin/s read text ex $1 >> HERE text HERE I don't get any errors either, so i don't know what i'm doing wrong. (7 Replies)
Discussion started by: Bertieboy7
7 Replies

3. Shell Programming and Scripting

How to retain backslash in a line while reading a data file?

Hello Firends I have a file that contains data within single quotes, which has meaning of its own. When I am trying to parse through the file for a different functionality I noticed that I was loosing the backslash when occurrences in the file look like ('\0'). I would want to retain the... (3 Replies)
Discussion started by: easwam
3 Replies

4. Shell Programming and Scripting

Shell script - paralllel reading problem

I have a shell script which has awk utlilty,also,in it. This a single script that many other jobs (informatica) using. Each job ll generate a log file. This script will read the particular log file and need to give output. The log file is act as input file for the script. So , a single script used... (2 Replies)
Discussion started by: Gopal_Engg
2 Replies

5. Shell Programming and Scripting

Reading from Keyboard - Shell Script

How do i read from kb using shell script but i need to read it from same line. Script :- echo "Please Enter Your Choice " read CHOICE But it goes to next line i need it to read it next to Choice and not new line. (4 Replies)
Discussion started by: dinjo_jo
4 Replies

6. Shell Programming and Scripting

Problem in expect script with password involving trailing backslash

Hi all, I have wriiten an expect script that genearates a public private key pair through ssh-keygen and then copies that key to the authorized keys file of the remote system . The problem i am facing is when i get a password for the remote machine containg a trailing backslash , the send command... (4 Replies)
Discussion started by: pradeeptyagi23
4 Replies

7. Shell Programming and Scripting

perl string matching problem (two backslash)

I have a few .tex files generated with html2latex. They have some extra \\ that generate error with pdflatex, so I would like to get rid of them. This perl -p -i -e s/\\\\//g myfile.tex with or without simple or double quote remove all of the backslashes, also the single ones needed by tex. How... (2 Replies)
Discussion started by: ahsog
2 Replies

8. Shell Programming and Scripting

File reading problem via shell script

Hi, Data file named parameter contains : DB=y Alter_def.sql Create_abc.sql SQL=y database.sql my_data.sql To read this file I use var_sql=$(awk -F= '$1 == "SQL" { print $2 }' parameter.txt) if then sql_f_name=`grep "\.sql" parameter.txt` echo $sql_f_name fi (2 Replies)
Discussion started by: Dip
2 Replies

9. Shell Programming and Scripting

file reading through shell script

For reading a file through shell script I am using yhe code : while read line do echo $line done<data.txt It reads all the line of that file data.txt. Content of data.txt looks like: code=y sql=y total no of sql files=4 a.sql b.sql c.sql d.sql cpp=n c=y total no of c files=1 (4 Replies)
Discussion started by: Dip
4 Replies

10. Shell Programming and Scripting

Reading a table in a shell script

Dear all: I want to write a script capable of reading specific rows and collumns of a table, into a variable. Just imagine i have a file named table.dat which contains: GENERAL INFORMATION Col 1 Col2 Col3 1 1 2 2 3 3 4 4 What i want to do... (13 Replies)
Discussion started by: luiscarvalheiro
13 Replies
Login or Register to Ask a Question