LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-04-2013, 10:21 AM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,153

Rep: Reputation: 303Reputation: 303Reputation: 303Reputation: 303
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
 
Old 03-04-2013, 10:39 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
The shell counts from zero:
Code:
$ R=${D:0:3}
$ echo "The value of R is: "$R
The value of R is: abc
 
1 members found this post helpful.
  


Reply

Tags
bash, string


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash -D (or bash --dump-strings) unexpected result Ubx Linux - General 2 02-24-2011 07:41 PM
Unexpected result in while do done loop reading file steven.c.banks Linux - General 2 05-01-2008 01:32 PM
mysql count(*) unexpected result kpachopoulos Programming 3 01-03-2008 11:08 AM
MySQL queries from Shell - unexpected result philipz Programming 5 05-04-2004 06:38 PM
cp command problem..... unexpected result hamster Linux - General 2 04-10-2003 05:57 PM


All times are GMT -5. The time now is 06:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration