Results 1 to 3 of 3

Thread: Escaping a \

  1. #1
    Join Date
    Mar 2004
    Posts
    10

    Unanswered: Escaping a \

    I want to include an argument that contains a \ in one of the commands. These arguments are in a file (one in a line). Ex:

    C:\
    D:\

    If I perform a while loop to read these lines,

    while read varName
    do
    echo $varName
    done < $argFile

    the loop exits without executing even once. How do I read these variables by escaping the \ ?

    Thanks.

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    If the last char of the line is \, 'read' assume that there is a continuation line.
    A solution is to escape the \ :
    'C:\' must be converted to 'C:\\' before 'read'
    Code:
    sed 's/\\$/\\\\/' $argFile | \
    while read varName
    do
       echo $varName
    done
    Jean-Pierre.

  3. #3
    Join Date
    Mar 2004
    Posts
    10
    That seems to work!! Thanks buddy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •