Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2005
    Posts
    1

    Unanswered: Can't stop shell interpreting special characters

    I am struggling with the following sample code:

    Code:
    array1=(a b c d)
    array2=(* * * *)
    
    print ${array1[2]}
    print ${array2[2]}
    It returns 'c' and the name of a file in the directory I'm in.

    I can't for the life of me work out how to prevent the shell interpreting the '*' and just get it to return the plain character ... is there a way to do this?


    Also, my Learning the Korn Shell book lists several sed-like functions you can use to edit variable names, e.g.

    Code:
    variable=string
    variable=${variable/g/gs}
    print $variable
    returns 'strings'. But Sed has a function where you can 'store' part of the pattern matched, and get it back in the replacement string, e.g.

    Code:
    print $variable | sed "s/\(strin\)g/\1/"
    returns 'strin'. Does the Korn shell have a similar feature that's not in my book?
    Last edited by Doug97; 11-23-05 at 19:36.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by Doug97
    I can't for the life of me work out how to prevent the shell interpreting the '*' and just get it to return the plain character
    In your case shell is interpreting *, not '*'

Posting Permissions

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