Ash Arithmetic Syntax Error
Contents |
/ shell scripting question / abort after Arithmetic Evaluation Messages sorted by: [ date ] arithmetic syntax error in shell script [ thread ] [ subject ] [ author ] Hi ksh arithmetic syntax error Bastian, 2015-06-24 23:03 GMT+02:00 Bastian Bittorf
Syntax Error Invalid Arithmetic Operator
> 2 > HERE > > root at box:~ a=; echo $(( a / 60 )); echo HERE > 0 > HERE > > root at box:~ a=; echo $(( $a / 60 )); echo HERE > -ash: arithmetic syntax error > > root at box:~ echo $(( / 60 )); echo syntax error invalid arithmetic operator (error token is .0 ) HERE > -ash: arithmetic syntax error > > can somebody explain, why the execution stopped > totally in the last 2 examples? this was the root-cause > for a not removed 'lock'-dir in one of our scripts... I think it is copied from Bash behavior. According to bash(1) doc: (section ARITHMETIC EVALUATION) > A shell variable that is null or unset evaluates to 0 when referenced by name without using the parameter expansion syntax. The last example is a *true* syntax error (the numerator is missing in the division). The third is equivalent to the last because `$a` is empty and being replaced with nothing. Cheers, Xabier Oneca_,,_ Previous message: ash / shell scripting question / abort after Arithmetic Evaluation Next message: ash / shell scripting question / abort after Arithmetic Evaluation Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] More information about the busybox mailing list
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 syntax error invalid arithmetic operator (error token is .5 ) with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack
Bash Shell Arithmetic
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
Linux Shell Math
Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top arithmetic syntax error in string compare up vote 2 down vote favorite I have written a shell script which http://lists.busybox.net/pipermail/busybox/2015-June/083049.html takes file name as parameter e.g user/test.txt. I want to make this file parameter optional if user does not wish to provide file name he/she can give as "None" Inside script I'm just checking if filename parameter contains "None" if [ $filename -eq "NONE" ];then cmd; fi When "None" is passed as parameter script works fine but when user/test.txt is passed I get below error message which I don't want to print on console arithmetic syntax error Can somebody help ? shell shell-script test share|improve http://unix.stackexchange.com/questions/220333/arithmetic-syntax-error-in-string-compare this question edited Aug 5 '15 at 22:22 Gilles 369k666681119 asked Aug 5 '15 at 13:23 chhaya vishwakarma 210411 consider using bash's argument handling. It will help you be more consistent with other programs. –richard Aug 5 '15 at 13:28 3 Not part of this problem, but I'd put quotes around that variable ("$filename") in case, e.g., you end up with spaces in there. –goldilocks Aug 5 '15 at 13:36 1 @goldilocks, spaces or any character in$IFS, or wildcard characters. Funny how the quotes are put where they're not needed ("NONE") and not where they're needed (typical beginner mistake as that's true that it's counter-intuitive to anyone used to other kinds of languages). Note that [ itself is a glob character, though because it's not matched in a single word (or as a special case for zsh), it doesn't need to be quoted. –Stéphane Chazelas Aug 5 '15 at 14:26 add a comment| 1 Answer 1 active oldest votes up vote 7 down vote accepted [ bla bla bla ] is equivalent to test bla bla bla. From man test STRING1 = STRING2 the strings are equal STRING1 != STRING2 the strings are not equal INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2 Therefore you need = not -eq. share|improve this answer edited Aug 5 '15 at 13:43 answered Aug 5 '15 at 13:26 richard 5,25311234 1 Ah!! I did silly mistake ..thanks for your answer –chhaya vishwakarma Aug 5 '15 at 13:36 It is traditional t
being changed to conform with the POSIX 1003.2 and 1003.2a specifications for the shell. This version has many features which make it appear similar in some respects to the Korn shell, but it is not a Korn https://linux.die.net/man/1/ash shell clone (see ksh(1)). Only features designated by POSIX, plus a few Berkeley extensions, are http://www.linuxquestions.org/questions/programming-9/bash-arithmetic-syntax-errors-897260/ being incorporated into this shell. We expect POSIX conformance by the time 4.4 BSD is released. This man page is not intended to be a tutorial or a complete specification of the shell. Overview The shell is a command that reads lines from either a file or the terminal, interprets them, and generally executes other commands. It is the syntax error program that is running when a user logs into the system (although a user can select a different shell with the chsh(1) command). The shell implements a language that has flow control constructs, a macro facility that provides a variety of features in addition to data storage. It incorporates many features to aid interactive use and has the advantage that the interpretative language is common to both interactive and non-interactive use (shell scripts). That is, arithmetic syntax error commands can be typed directly to the running shell or can be put into a file and the file can be executed directly by the shell. Invocation If no args are present and if the standard input of the shell is connected to a terminal (or if the -i flag is set), and the -c option is not present, the shell is considered an interactive shell. An interactive shell generally prompts before each command and handles programming and command errors differently (as described below). When first starting, the shell inspects argument 0, and if it begins with a dash '-', the shell is also considered a login shell. This is normally done automatically by the system when the user first logs in. A login shell first reads commands from the files /etc/profile and .profile if they exist. If the environment variable ENV is set on entry to a shell, or is set in the .profile of a login shell, the shell next reads commands from the file named in ENV. Therefore, a user should place commands that are to be executed only at login time in the .profile file, and commands that are executed for every shell inside the ENV file. To set the ENV variable to some file, place the following line in your .profile of your home directory ENV=$HOME/.shinit;
Search Tutorials/Articles Search HCL Search Reviews Search ISOs Go to Page... LinuxQuestions.org > Forums > Non-*NIX Forums > Programming bash Arithmetic Syntax Errors User Name Remember Me? 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 Welcome to LinuxQuestions.org, a friendly and active Linux Community. You are currently 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 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. Page 1 of 2 1 2 > Search this Thread 08-14-2011, 12:35 PM #1 MTK358 LQ 5k Club Registered: Sep 2009 Posts: 6,443 Blog Entries: 3 Rep: bash Arithmetic Syntax Errors I tried writing the following in my .bashrc, it's supposed to draw a bar across the top of the terminal (containing information like the surrent directory and exit code of the previous command) whenever the prompt is shown. Code: # custom prompt function create-prompt-infobar { local i=0 if (($COLUMNS >= (${#PWD} + ${#?} + 11))); then echo -n "$PWD" for ((i=0; i<($COLUMNS-${#PWD}-${#?}-10); i++)); do echo ""; done echo -n "exitcode: ${?}" elif (($COLUMNS >= ${#PWD})); then echo "$PWD" for (($i=0; $i<($COLUMNS-${#PWD}); $i++)); do echo "