Bad Number Error In Unix
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 Learn more about Stack Overflow the company Business Learn more about hiring developers or posting bad substitution error in unix ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join
How To Redirect Error In Unix
the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a
Standard Error Unix
minute: Sign up Shell script programming : “bad number” error up vote 1 down vote favorite I am writing a simple shell script and I am having a strange error about "bad number". Here is my code : status=0 maxRetries=3 retryCount=1
Unix Redirect 2 &1
while [[ status == 0 ]] || [[ retryCount -le maxRetries ]] do .... retryCount=$((retryCount+1)) done As far as I see, I have properly declared maxRetries and retryCount as integers, so I don't see why it complains about bad number on the while statement. Anyone have an idea? linux shell share|improve this question asked Oct 4 '13 at 0:40 Mickaël C. Guimaraes 7118 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted status, retryCount and maxRetries sql error numbers are strings, not numbers. You want to expand those parameters with the $ sigil. Alternatively, you could use arithmetic expressions, which do not require the sigil. while (( status == 0 || retryCount < maxRetries )) share|improve this answer answered Oct 4 '13 at 0:41 kojiro 40.8k964111 status, is also missing a $ –sampson-chen Oct 4 '13 at 0:43 Allright, now it's working. So simple... Thank you! –Mickaël C. Guimaraes Oct 4 '13 at 0:43 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged linux shell or ask your own question. asked 2 years ago viewed 2726 times active 2 years ago Related 2103Check if a directory exists in a shell script721How do I prompt for input in a Linux shell script?389Why doesn't “cd” work in a bash shell script?225Get program execution time in the shell975Check if a program exists from a Bash script239Aborting a shell script if any command returns a non-zero value?351Shell command to tar directory excluding certain files/folders337How can I write a here doc to a file in Bash script?0Display numbers shell scripting6Debugging shell scripts with line numbers Hot
Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, windows error numbers HP-UX, AIX, OS X, BSD. Search Forums Show Threads Show Posts oracle error numbers Tag Search Advanced Search Unanswered Threads Find All Thanked Posts Go to Page... learn linux and shift bad number unix commands - unix shell scripting Bad Number Error UNIX for Advanced & Expert Users Thread Tools Search this Thread Display Modes http://stackoverflow.com/questions/19171362/shell-script-programming-bad-number-error #1 06-29-2006 moan71 Registered User Join Date: Jun 2006 Last Activity: 4 October 2006, 8:00 PM EDT Posts: 2 Thanks: 0 Thanked 0 Times in 0 Posts Bad Number Error What is wrong with my syntax, I am getting bad number error. The following lines of code get the value from INI file but the variable is http://www.unix.com/unix-for-advanced-and-expert-users/28752-bad-number-error.html a combination of multiple variables. When compiling all together, I get a bad number error or changing the '((' with '{{' gets me bad substitution error. The code works if the return value is a numeric but it fails when it is a TXT. What is the best way to tackle this, any one? INI Example is at the end SERV_CNT=1 function start { TOT_SERV=`echo NUMBER_OF_${APPLICATION}_SERV` while [[ $SERV_CNT -le $TOT_SERV ]] do #SERVER=${FIN_P1_[$SERV_CNT]} SERVER=$((${APPLICATION}_${SERV}_[$SERV_CNT])) #$WEB_HOME/$START_SCRIPT $SERVER let SERV_CNT=$SERV_CNT+1 done } INI File: NUMBER_OF_FIN_SERV=6 FIN_P1_[1]=FINPROD FIN_P1_[2]=FINPROD02 FIN_P1_[3]=FINPROD03 FIN_P1_[4]=FINPROD04 FIN_P1_[5]=FINPROD05 FIN_P1_[6]= FINPROD06 Remove advertisements Sponsored Links moan71 View Public Profile Find all posts by moan71 #2 06-29-2006 Perderabo Unix Daemon (Administrator Emeritus) Join Date: Aug 2001 Last Activity: 26 February 2016, 12:31 PM EST Location: Ashburn, Virginia Posts: 9,931 Thanks: 64 Thanked 462 Times in 267 Posts Here is one way... Code: $ cat x #! /usr/bin/ksh SERV_CNT=1 function start { eval TOT_SERV=\$NUMBER_OF_${APPLICATION}_SERV while [[ $SERV_CNT -le $TOT_SERV ]] ; do eval SERVER=\${${APPLICATION}_${SERV}_[SERV_CNT]} echo $SERV_CNT $SERVER ((SERV_CNT=SERV_CNT+1)) done return 0 } NUMBER_OF_
Display results as threads More... Useful Searches Recent Posts Menu Forums Forums Quick Links Search Forums Recent Posts Menu https://forums.anandtech.com/threads/more-unix-shell-scripting-help-needed-bad-number-ksh.2173555/ Log in Sign up AnandTech Forums: Technology, Hardware, Software, and Deals Forums > Software > Programming > More UNIX Shell Scripting Help Needed "Bad Number" (KSH) Discussion in 'Programming' http://unix.stackexchange.com/questions/230457/how-to-skip-the-first-argument-in-a-script started by Saint Nick, Jun 22, 2011. Saint Nick Lifer Joined: Jan 21, 2005 Messages: 17,723 Likes Received: 0 Here is my code Code: #!/usr/bin/ksh clear file=/home/x12960/apedi.dat line_nbr=0 next_line_nbr=`expr error in ${line_nbr} + 1` file_lines=`wc -l ${file}` outfile=new_apedi.dat #echo $file #echo $line_nbr #echo $next_line_nbr #echo $file_lines #echo $outfile while [[ $line_count -lt $file_lines ]] do line=`sed -n "${line_nbr}p" $file` next_line=`sed -n "${next_line_nbr}p" $file` line_char=`echo $line | cut -c1-1` next_line_char=`echo $next_line | cut -c1-1` if [[ $line_char = "H" ]] ; then if [[ $line_char -eq $next_line_char ]] ; error in unix then echo $next_line >> $outfile fi else echo $line >> $outfile fi if [[ $next_line_nbr -eq $file_lines ]] ; then line_nbr=`expr $line_nbr + 1` next_line_nbr=$next_line_nbr else line_nbr=`expr $line_nbr + 1` next_line_nbr=`echo ${line_nbr}` fi done But, when I run it, I am getting the following error: Code: ./apedi.scr[9]: 22 /home/x12960/apedi.dat: bad number In my file, line 9 is outfile=new_apedi.dat. I'd like to add that when I un-comment my echo statements, the same error shows up, but states it is at line 15 rather than line 9. Also, there are 22 lines in my test file. Thanks for the help! #1 Saint Nick, Jun 22, 2011 Last edited: Jun 22, 2011 Saint Nick Lifer Joined: Jan 21, 2005 Messages: 17,723 Likes Received: 0 Turns out that wc also returns the name of the file in the count...how can I get rid of that? There doesn't seem to be a command line option for it... :hmm: Bleh. Fixed it. Updated the wc line to the following. Code: file_lines=`wc -l ${file} | awk '
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 Business Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only 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 How to skip the first argument in a script up vote 0 down vote favorite Linux Pocket Guide has a nice example on how to go over all the arguments in a script for arg in $@ do echo "I found the argument $arg" done I am writing a script in which all the arguments will be text files, and I will concatenate all those text files and print them to stdout, however I should exclude the contents of the first argument. My first approach would be something like this for arg in $@ do cat "$arg" done However, that will include the first argument, and as I mentioned, I want to print all except the first one. shell shell-script share|improve this question edited Sep 18 '15 at 4:43 cuonglm 71.1k13111196 asked Sep 18 '15 at 3:35 Haz 334 1 As a side note, "$@" should always be quoted. Another side note, you can get the same functionality without the for loop: cat "$@". –jordanm Sep 18 '15 at 3:40 add a comment| 4 Answers 4 active oldest votes up vote 5 down vote accepted You can use shift command like this: shift for arg in "$@" do cat "$arg" done share|improve this answer edited Sep 18 '15 at 3:43 cuonglm 71.1k13111196 answered Sep 18 '15 at 3:42 alcik 30917 add a comment| up vote 1 down vote You