LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Bash substring delivers unexpected result (http://www.linuxquestions.org/questions/programming-9/bash-substring-delivers-unexpected-result-4175452646/)

danielbmartin 03-04-2013 09:21 AM

Bash substring delivers unexpected result
 
Code:

daniel@daniel-desktop:~$ D="abcdefghi"
daniel@daniel-desktop:~$ R=${D:1:3}
daniel@daniel-desktop:~$ echo "The value of R is: "$R
The value of R is: bcd

I expected abc, not bcd.

Please advise.

Daniel B. Martin

colucix 03-04-2013 09:39 AM

The shell counts from zero:
Code:

$ R=${D:0:3}
$ echo "The value of R is: "$R
The value of R is: abc

:)


All times are GMT -5. The time now is 03:07 PM.