Bash Array Value Too Great For Base Error Token Is
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us
Value Too Great For Base Error Token Is 09 Linux
Learn more about Stack Overflow the company Business Learn more about hiring developers bash value too great for base 08 or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack
Value Too Great For Base (error Token Is 08 )
Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up value to great for base error from value too great for base date bash associative array up vote 2 down vote favorite I have a file called a.txt which looks as follow 7A1123123asd 14 8aasdasdasd 15 Now I wrote some bash code to read the file and build an associative array from the values in it #!/bin/bash declare -a counter while read DEAL count; do counter["$DEAL"]=$count done < oasload.job for i in "${!array[@]}" do echo "key : $i" echo "value value too great for base (error token is 0008 ) : ${array[$i]}" done Unfortunately when I run I get the following error test.sh: line 6: 7A1123123asd: value too great for base (error token is "7A1123123asd") Any help appreciated. bash associative-array share|improve this question edited Feb 18 '11 at 22:55 marcog 59.6k32152187 asked Feb 18 '11 at 22:53 puneet 112 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote Looks like bash treats keys starting with digits as numeric. So, trying to convert 7A it balks because A is not a valid base-10 digit. If you can e.g. prefix all your keys with X throughout, this should fix it. #!/bin/bash declare -a counter while read DEAL count; do counter["X$DEAL"]=$count done < oasload.job for i in "${!array[@]}" do echo "key : $i" echo "value : ${array[$i]}" done share|improve this answer answered Feb 18 '11 at 23:06 Erik 52.2k7133156 declare -a foo; foo["Xa1"]=1; foo["Xz9"]=2; echo "first: ${foo["Xa1"]}, second: ${foo["Xz9"]}, indices: ${!foo[@]}" gives "first: 2, second: 2, indices: 0" –Dennis Williamson Feb 19 '11 at 0:19 Hi what does the X mean? –Simonlbc Aug 16 at 12:24 add a comment| up vote 1 down vote Everything looks OK except that in Bash 4, associative
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company
Bash Base 10\
Business Learn more about hiring developers or posting ads with us Ask Ubuntu Questions Tags bash force base 10 Users Badges Unanswered Ask Question _ Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only
Value Too Great For Base (error Token Is 008 )
takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Bash 12 - 08 Value too great for base (error http://stackoverflow.com/questions/5047424/value-to-great-for-base-error-from-bash-associative-array token “08”) up vote 2 down vote favorite So, I'm trying to calculate 12-08 (not 12-8) and get the following error: let: 08: value too great for base (error token is "08") Here's the sample code: first=12 second=08 if [[ ($first > $second) ]]; then let fin=first-second else let fin=second-first fi P.S Sorry about the spacings bash scripts share|improve this question edited May 9 at 11:15 terdon♦ 41.5k685150 asked May 9 at 11:03 EmberSpirit 172 3 http://askubuntu.com/questions/769722/bash-12-08-value-too-great-for-base-error-token-08 See Why does bash thinks that 010 is 8? –steeldriver May 9 at 11:11 add a comment| 1 Answer 1 active oldest votes up vote 7 down vote If you precede a number by 0, bash treats the number as octal. As octal is base 8 with digits ranging from 0 to 7, 08 is out of range for octal. Now you have two options to do decimal calculation: Omit preceding 0: $ echo $(( 12 - 8 )) 4 Explicitly mention base as decimal by 10#: $ echo $(( 12 - 10#08 )) 4 share|improve this answer edited May 9 at 15:14 Community♦ 1 answered May 9 at 11:11 heemayl 42.3k776129 2 @cat it's also used in i) the shebang line (#!/bin/bash); ii) string manipulation (var="foo"; echo ${var#f}); iii) the $# variable; iv) the !# variable and a few other fringe cases here and there :) Have a look at man bash | grep '#'. –terdon♦ May 9 at 16:01 @cat: # only starts a comment when used at the beginning of a word. –deltab May 9 at 16:31 At the beginning of a word; e.g. echo foo#bar #baz will output foo#bar but not #baz, because the latter starts a comment. –deltab May 9 at 19:52 add a comment| Your Answer draft saved draft discarded Sign up or log
Tags Search LQ Wiki Search Tutorials/Articles Search HCL Search Reviews Search ISOs Go to Page... LinuxQuestions.org > Forums > Linux Forums > Linux - General http://www.linuxquestions.org/questions/linux-general-1/bash-scripting-value-too-great-for-base-error-token-is-08-a-824649/ Bash scripting: value too great for base (error token is "08") User Name Remember Me? Password Linux - General This Linux forum is for general Linux questions and discussion. If it http://www.tek-tips.com/viewthread.cfm?qid=1133283 is Linux Related and doesn't seem to fit in any other forum then this is the place. Notices Welcome to LinuxQuestions.org, a friendly and active Linux Community. You are currently value too viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today! Note that registered members see fewer ads, and ContentLink is completely disabled once you log in. Are you value too great new to LinuxQuestions.org? Visit the following links: Site Howto | Site FAQ | Sitemap | Register Now If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here. Having a problem logging in? Please visit this page to clear all LQ-related cookies. Introduction to Linux - A Hands on Guide This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own. Click Here to receive this Complete Guide absolutely free. Sear
Join INTELLIGENT WORK FORUMSFOR COMPUTER PROFESSIONALS Log In Come Join Us! Are you aComputer / IT professional?Join Tek-Tips Forums! Talk With Other Members Be Notified Of ResponsesTo Your Posts Keyword Search One-Click Access To YourFavorite Forums Automated SignaturesOn Your Posts Best Of All, It's Free! Join Us! *Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting Guidelines Promoting, selling, recruiting, coursework and thesis posting is forbidden.Tek-Tips Posting Policies Jobs Jobs from Indeed What: Where: jobs by Link To This Forum! Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.Just copy and paste the BBCode HTML Markdown MediaWiki reStructuredText code below into your site. Linux (server) Forum at Tek-Tips HomeForumsMIS/ITOperating Systems - UNIX basedLinux (server) Forum shell script - pls help thread54-1133283 Forum Search FAQs Links MVPs shell script - pls help shell script - pls help santanudas (TechnicalUser) (OP) 6 Oct 05 12:06 hi guys,Need to write a bash script which will increment the numbers by 1 but the number should be with leading zero, i.e. 01, 02, 03 etc.So, if I do#!/bin/bashs=`seq -w 5 12`for i in $sdoecho $[i+1]done not returning the desired result. I tried replacing“$[i+1]” with “$[s+1]” and that doesn't work too. What wrong am I doing? Any guys out here to help?Thanks in advance. RE: shell script - pls help thedaver (IS/IT--Management) 6 Oct 05 14:09 Why not just write the "for" using 01 02 03 04 05 06 ....? D.E.R. Management - IT Project Management Consultinghttp://www.dermanagement.com/ RE: shell script - pls help ericbrunson (TechnicalUser) 6 Oct 05 14:26 You're going to run into a problem, since bash interprets numbers with a leading zeor as octal, so when you try to do 08, you'll get an error because it's not a valid number.Other than that, you could use 'printf "%02d\n" $[i+1]' to get your formatting.You'll have to strip off the leading zeros before you do the addition. RE: shell script - pls help santanudas (TechnicalUser) (OP) 6 Oct 05 17:01 thedaver, `seq 5 12` was just an example. Actually what I’m doing is:r=`ls /some-dir/ | wc -l`s=`seq -w 1 ${r}`so, I know the number. Right now it’s 57; no won