LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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
 
LinkBack Search this Thread
Old 06-27-2012, 10:36 AM   #1
shadyabhi
LQ Newbie
 
Registered: Sep 2008
Posts: 20

Rep: Reputation: 0
Why do I need a space here?


Is there a reason behind requiring a space?
Or at lease a logic behind why was it done like that?

Code:
shadyabhi@MBP-archlinux ~ $ array=( zero one two three four five )
shadyabhi@MBP-archlinux ~ $ echo ${array[@]:-1:1}
zero one two three four five
shadyabhi@MBP-archlinux ~ $ echo ${array[@]: -1:1}
five
shadyabhi@MBP-archlinux ~ $
I observed above that if I don't give a space between "]:" and "-1", something troublesome happens.
 
Old 06-27-2012, 11:01 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
http://wiki.bash-hackers.org/syntax/...ring_expansion, scroll down to "Negative offset value".

Essentially, otherwise the ':-' is interpreted as the syntax for a default value:

Code:
$ echo ${undefined_variable:-1:1}
1:1
You could also put brackets around the (-1) instead of putting a space before it.
 
1 members found this post helpful.
Old 06-27-2012, 11:08 PM   #3
shadyabhi
LQ Newbie
 
Registered: Sep 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Snark1994 View Post
http://wiki.bash-hackers.org/syntax/...ring_expansion, scroll down to "Negative offset value".

Essentially, otherwise the ':-' is interpreted as the syntax for a default value:
Thanks Snark1994. Also, the website looks like a great resource and interesting to read too. I always used to go to TLDP and search for stuff but this one seems more interesting.
 
  


Reply

Tags
bash, bash scripting


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
partition space and disk space usage and free don't match nsic Linux - Newbie 3 02-22-2013 12:57 PM
Unable to read the updated buffer in kernel space from user space raju_1234 Linux - Embedded & Single-board computer 0 06-20-2012 01:50 AM
Division of Logical Memory Space in to User Space and Kernel Space shreshtha Linux - Newbie 2 01-14-2010 09:59 AM
how to call socket prog code written in user space from kernel space???HELP kurt2 Programming 2 07-15-2009 09:56 PM
LXer: Worms in space: NASA confirms International Space Station infected LXer Syndicated Linux News 0 08-28-2008 09:40 AM


All times are GMT -5. The time now is 12:54 PM.

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