Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, I'm trying to use ${VAR:0:4} substring extraction described here: tldp.org/LDP/abs/html/string-manipulation.html and it works perfectly if i issue a command in bash. But when i put it in a script ...
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    3

    Substring Extraction

    Hi,

    I'm trying to use ${VAR:0:4} substring extraction described here:

    tldp.org/LDP/abs/html/string-manipulation.html

    and it works perfectly if i issue a command in bash.

    But when i put it in a script file and run it, bash gives me "bad substitution" error.

    Does anyone know how to fix it?

    Thanks

  2. #2
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    You may pecise things with sufficient portion of your code to generate the error.
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

  3. #3
    Just Joined!
    Join Date
    Jul 2010
    Posts
    3
    sorry, didn't get that

  4. #4
    Linux Newbie
    Join Date
    Mar 2010
    Posts
    121
    Quote Originally Posted by romanart View Post
    sorry, didn't get that
    He meant that he wanted you to post code we could run that generates the error, so we can tell you what's going wrong.

    However, I reckon the first like of your script is:

    Code:
    #!/bin/sh
    If so, change that to:

    Code:
    #!/bin/bash
    and all should be dandy.

  5. #5
    Just Joined!
    Join Date
    Jul 2010
    Posts
    3
    that was it. Thanks a lot!

  6. #6
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    JohnGraham, I'm amazed, you see clearly in the dark !
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

Posting Permissions

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