LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-12-2005, 11:48 AM   #1
zz9pluralzalpha
Member
 
Registered: Jun 2004
Location: UK
Distribution: BLFS 5.1
Posts: 34

Rep: Reputation: 15
bash scripting problem (bug?)


I've developed a neat little bash script to find the shortest relative path from one directory to anonther, for symlinking purposes. It operates on lists of directories and in particular, makes use of bash's ${a[@]:$x} notation for finding sublists (where $a is a list and $x is an integer). For example, suppose I do
Code:
a=( foo bar superstar )
then
Code:
echo ${a[@]:0}
gives
Code:
foo bar superstar
likewise, I get
Code:
echo ${a[@]:1}
bar superstar
but
Code:
echo ${a[@]:2}
returns blank. Nothing. I was expecting "superstar". In other words,

Code:
[ "x${a[@]:$((${#a[@]}-1))}" = "x${a[$((${#a[@]}-1))]}" ]; echo $?
prints nothing for a given list $a.

Am I doing something wrong? I'm using Bash 3.00.0
 
Old 04-12-2005, 11:56 AM   #2
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
Hrm, might be your version of bash:

Code:
bash --version
GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.

(* jhill@leper pts/5 12:54 PM 35 *) - /etc/sysconfig
> a=( foo bar superstar )

(* jhill@leper pts/5 12:55 PM 40 *) - /etc/sysconfig
> for i in 0 1 2 3;do echo ${a[@]:$i}; done
foo bar superstar
bar superstar
superstar

(* jhill@leper pts/5 12:55 PM 41 *) - /etc/sysconfig
So I do get the blank line on #3
 
Old 04-12-2005, 01:51 PM   #3
zz9pluralzalpha
Member
 
Registered: Jun 2004
Location: UK
Distribution: BLFS 5.1
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks.

I think you may be right. I'm upgrading from LFS 5.1 to 6.0 so I have bash 2 and 3.

Anyway I pasted your code in to 2.05b and it worked fine. Then I pasted mine in and it worked fine. But 3.00.0 still seems to choke.

Thanks

Last edited by zz9pluralzalpha; 04-12-2005 at 02:00 PM.
 
  


Reply


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 scripting problem sutley Linux - Software 1 12-17-2004 11:33 AM
bash scripting problem Sammy2ooo Linux - General 3 12-13-2004 12:31 PM
BASH Scripting Design Problem... amaze Linux - General 1 08-19-2003 08:30 AM
BASH scripting problem deadlock Programming 5 08-15-2003 04:33 AM
bash scripting problem raven Programming 7 03-10-2003 05:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:48 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration