MoonPoint Support Logo


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals

Advanced Search
Sun Mon Tue Wed Thu Fri Sat

Thu, Sep 08, 2011 9:33 pm

Bash Calculator

If you need to do quick calculations on a system that provides the Bash shell, such as Linux or Mac OS X, you can perform calculations by using the echo command and then using $[ and ] to enclose the arithmetic calculation, i.e., echo $[calculation to be performed]. You can use the standard arithmetic operators of + for addition, - for subtraction, * for multiplication, / for division, and ** for exponentiation.
$ echo $[1+1]
$ echo $[9*90]
$ echo $[81/9]
$ echo $[2**3]

The standard precedence for operators applies, i.e., multiplication and division have precedence over addition and subtraction, so are performed first, i.e., the calcuations are not simply done on a left to right basis.

$ echo $[2+3*4]
$ echo $[6-4/2]

This Bash calculator functionality even handles negative numbers appropriately.

$ echo $[-4*5]
$ echo $[-4*-5]


  1. When you need a quick & simple calculator in Bash...
    TinyApps.Org, small is beautiful
  2. Bash (Unix shell)
    Wikipedia, the free encyclopedia

[/os/unix/bash] permanent link

Thu, Sep 08, 2011 9:25 pm

Retrieving Password Protected Webpages Using HTTPS With Curl

Mac OS X systems come with the curl command line tool which provides the capability to retrieve web pages from a shell prompt. To use the tool, using Finder on the system, you can go to Applications, Utilities and double-click on Terminal to obtain a shell prompt.

Curl is also available for a variety of other operating systems, including DOS, Linux, and Windows. Versions for other operating systems can be obtained from cURL - Download. If you will be retrieving encrypted webpages using the HTTPs protocol, be sure to get the binary version that includes Secure Sockets Layer (SSL) support.

A program with similar functionality is Wget, but that isn't included by default with the current versions of the Mac OS X operating system.

On Mac OS X systems, curl is available in /usr/bin and help on the options for curl can be found using man curl, curl -h , curl --help, and curl --manual. An online manual can be viewed at cURL - Manual.

To retrieve a webpage that requires a userid and password for access with curl using the HTTPS protocol, you can use a command similar to the one below where userid and password represent the userid and password required to access that particular webpage.

curl -u userid:password

If you don't want to include the password on the command line, you can just specify the userid after the -u; curl will then prompt you for the password.

$ curl -u jsmith
Enter host password for user 'jsmith':

If you wish to save the output in a file rather than have it go to stdout, i.e., rather than have it appear on the screen, you can use the -o/--output filename option where filename is the name you wish to use for the output file. Curl will provide information on the number of bytes downloaded and the time that it took to download a webpage.

$ curl -u jsmith:somepassword -o somepage.html
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 22924    0 22924    0     0  16308      0 --:--:--  0:00:01 --:--:-- 26379


  1. cURL and libcurl

[/network/web/tools/curl] permanent link

Once You Know, You Newegg AliExpress by

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo