導航:首頁 > 程序命令 > linux命令行計算器

linux命令行計算器

發布時間:2022-10-30 09:54:27

Ⅰ 紅帽linux6.5 計算器指令

bc

帶小數就用 bc -l

Ⅱ linux下的bc計算器做出結果後答案怎麼復制

可以直接輸出到文件里。
你在原有執行的bc命令及其後的數和計算等一系列內容(你算數用的所有內容)之後空一個格,添加
>> filename
,filename是文件名,最好不是已經在當前目錄下已經存在的文件,否則會把結果附在原來文件的最後處。這樣執行bc過程中的全部輸出都不會出現在屏幕上,而是輸入到filename這個文件裡面。

Ⅲ linux計算器余數代碼怎麼寫

http://jingyan..com/article/1e5468f974a17a484861b770.html

Ⅳ Linux:如何在命令行里直接算加減乘除呢現在需要算東西我還要開個計算器=。=

echo $((2+5*9))
這樣,前面有個$,然後將算式放在括弧里(前後圓括弧各有兩個),這個只支持整數四則運算

Ⅳ 怎麼樣稱得上是Linux下優秀的命令行計算器

windows裡面在命令界面輸入calc就可以打開計算器,linux裡面輸入什麼命令可以打開計算器?比如我在terminal輸入firefox,它就打開了firefox。
我要輸入什麼才能打開計算器?
比如打開 畫圖板 word 控制面板 計算器 等這些 一些比較常用的工具 謝謝咯~!!

Ⅵ windows有沒有一個類似linux下的計算器命令行 bc 指令 ,求分享,謝謝!

沒有,因為windows是視窗操作系統,為了方便用戶操作,很少有命令行的常用應用程序。
linux是原生命令行系統,所以絕大多數的工具、程序都有命令行的版本。

Ⅶ 在Linux下,用shell編寫一個簡單的計算器,要實現加減乘除4個功能就行了

不用寫吧,本來有個 bc 命令可用,沒有下載就成.
非要寫一個,zsh 的function里有一個,名 zcalc,
貼上來給你

#!/usr/bin/zsh -i
#
# Zsh calculator. Understands most ordinary arithmetic expressions.
# Line editing and history are available. A blank line or `q' quits.
#
# Runs as a script or a function. If used as a function, the history
# is remembered for reuse in a later call (and also currently in the
# shell's own history). There are various problems using this as a
# script, so a function is recommended.
#
# The prompt shows a number for the current line. The corresponding
# result can be referred to with $<line-no>, e.g.
# 1> 32 + 10
# 42
# 2> $1 ** 2
# 1764
# The set of remembered numbers is primed with anything given on the
# command line. For example,
# zcalc '2 * 16'
# 1> 32 # printed by function
# 2> $1 + 2 # typed by user
# 34
# 3>
# Here, 32 is stored as $1. This works in the obvious way for any
# number of arguments.
#
# If the mathfunc library is available, probably understands most system
# mathematical functions. The left parenthesis must be adjacent to the
# end of the function name, to distinguish from shell parameters
# (translation: to prevent the maintainers from having to write proper
# lookahead parsing). For example,
# 1> sqrt(2)
# 1.4142135623730951
# is right, but `sqrt (2)' will give you an error.
#
# You can do things with parameters like
# 1> pi = 4.0 * atan(1)
# too. These go into global parameters, so be careful. You can declare
# local variables, however:
# 1> local pi
# but note this can't appear on the same line as a calculation. Don't
# use the variables listed in the `local' and `integer' lines below
# (translation: I can't be bothered to provide a sandbox).
#
# Some constants are already available: (case sensitive as always):
# PI pi, i.e. 3.1415926545897931
# E e, i.e. 2.7182818284590455
#
# You can also change the output base.
# 1> [#16]
# 1>
# Changes the default output to hexadecimal with numbers preceded by `16#'.
# Note the line isn't remembered.
# 2> [##16]
# 2>
# Change the default output base to hexadecimal with no prefix.
# 3> [#]
# Reset the default output base.
#
# This is based on the builtin feature that you can change the output base
# of a given expression. For example,
# 1> [##16] 32 + 20 / 2
# 2A
# 2>
# prints the result of the calculation in hexadecimal.
#
# You can't change the default input base, but the shell allows any small
# integer as a base:
# 1> 2#1111
# 15
# 2> [##13] 13#6 * 13#9
# 42
# and the standard C-like notation with a leading 0x for hexadecimal is
# also understood. However, leading 0 for octal is not understood --- it's
# too confusing in a calculator. Use 8#777 etc.
#
# Options: -#<base> is the same as a line containing just `[#<base>],
# similarly -##<base>; they set the default output base, with and without
# a base discriminator in front, respectively.
#
#
# To do:
# - separate zcalc history from shell history using arrays --- or allow
# zsh to switch internally to and from array-based history.

emulate -L zsh
setopt extendedglob

local line ans base defbase forms match mbegin mend psvar optlist opt arg
local compcontext="-math-"
integer num outdigits outform=1
# We use our own history file with an automatic pop on exit.
history -ap "${ZDOTDIR:-$HOME}/.zcalc_history"

forms=( '%2$g' '%.*g' '%.*f' '%.*E' )

zmodload -i zsh/mathfunc 2>/dev/null

: ${ZCALCPROMPT="%1v> "}

# Supply some constants.
float PI E
(( PI = 4 * atan(1), E = exp(1) ))

# Process command line
while [[ -n $1 && $1 = -(|[#-]*) ]]; do
optlist=${1[2,-1]}
shift
[[ $optlist = (|-) ]] && break
while [[ -n $optlist ]]; do
opt=${optlist[1]}
optlist=${optlist[2,-1]}
case $opt in
('#') # Default base
if [[ -n $optlist ]]; then
arg=$optlist
optlist=
elif [[ -n $1 ]]; then
arg=$1
shift
else
print "-# requires an argument" >&2
return 1
fi
if [[ $arg != (|\#)[[:digit:]]## ]]; then
print - "-# requires a decimal number as an argument" >&2
return 1
fi
defbase="[#${arg}]"
;;
esac
done
done

for (( num = 1; num <= $#; num++ )); do
# Make sure all arguments have been evaluated.
# The `$' before the second argv forces string rather than numeric
# substitution.
(( argv[$num] = $argv[$num] ))
print "$num> $argv[$num]"
done

psvar[1]=$num
while vared -cehp "${(%)ZCALCPROMPT}" line; do
[[ -z $line ]] && break
# special cases
# Set default base if `[#16]' or `[##16]' etc. on its own.
# Unset it if `[#]' or `[##]'.
if [[ $line = (#b)[[:blank:]]#('[#'(\#|)(<->|)']')[[:blank:]]#(*) ]]; then
if [[ -z $match[4] ]]; then
if [[ -z $match[3] ]]; then
defbase=
else
defbase=$match[1]
fi
print -s -- $line
line=
continue
else
base=$match[1]
fi
else
base=$defbase
fi

print -s -- $line

case ${${line##[[:blank:]]#}%%[[:blank:]]#} in
q) # Exit if `q' on its own.
return 0
;;
norm) # restore output format to default
outform=1
;;
sci[[:blank:]]#(#b)(<->)(#B))
outdigits=$match[1]
outform=2
;;
fix[[:blank:]]#(#b)(<->)(#B))
outdigits=$match[1]
outform=3
;;
eng[[:blank:]]#(#b)(<->)(#B))
outdigits=$match[1]
outform=4
;;
local([[:blank:]]##*|))
eval $line
line=
continue
;;
*)
# Latest value is stored as a string, because it might be floating
# point or integer --- we don't know till after the evaluation, and
# arrays always store scalars anyway.
#
# Since it's a string, we'd better make sure we know which
# base it's in, so don't change that until we actually print it.
eval "ans=\$(( $line ))"
# on error $ans is not set; let user re-edit line
[[ -n $ans ]] || continue
argv[num++]=$ans
psvar[1]=$num
;;
esac
if [[ -n $base ]]; then
print -- $(( $base $ans ))
elif [[ $ans = *.* ]] || (( outdigits )); then
printf "$forms[outform]\n" $outdigits $ans
else
printf "%d\n" $ans
fi
line=
done

return 0

支援小數點,+ - * / , ok

Ⅷ linux借用外部命令expr,實現計算器功能,利用管道,進程

test指令(使用指令man查詢)

功能:檢查文件類型,值比較。

test的各種參數和使用。

test EXPRESSION1 –a EXPRESSION2

當表達式1和表達式2同時為真時值為真

test EXPRESSION1 –o EXPRESSION2

當表達式1或者表達式2為真時值為真

test –n STRING

或者

test STRING

當STRING串的長度不為零時值為真

test –z STRING

當STRING串長度為零時值為真

test STRING1 = STRING2

當STRING1和STRING2相同時值為真

test STRING1 != STRING2

當STRING1 和 STRING2不同時值為真

test INTEGER1 –eq INTEGER2

當INTEGER1等於INTEGER2時值為真

test INTEGER1 –ge INTEGER2

當INTEGER1大於或者等於INTEGER2時值為真

test INTEGER1 –gt INTEGER2

當INTEGER1 大於INTEGER2時值為真

test INTEGER1 –le INTEGER2

當INTEGER1小於等於INTEGER2時值為真

test INTEGER1 –lt INTEGER2

當INTEGER1 小於INTEGER2時值為真

test INTEGER1 –ne INTEGER2

當INTEGER1不等於INTEGER2時值為真

test FILE1 –ef FILE2

當FILE1和FILE2有同樣的device和inode號時為真(詳細見linux文件學習筆記)

test FILE1 –nt FILE2

當FILE1修改時間比FILE2新時值為真

test FILE1 –ot FILE2

當FILE1修改時間比FILE2舊時值為真

test –b FILE

FILE存在並且內容是block類型的

test –c FILE

FILE存在並且是字元類型的

test –d FILE

FILE存在並且是一個目錄

test –e FILE

FILE是否存在

test –f FILE

FILE存在並且是一個正則表達式類型的文檔

test –g FILE

FILE存在並且是 set-group-ID也就是SGID(詳細見後文學習筆記)

test –G FILE

FILE存在並且由有效的GROUP ID所擁有(詳細見後文學習筆記)

test –h FILE

FILE存在並且是一個符號鏈接(詳細見後文學習筆記)

test –k FILE

FILE存在並且設置了sticky bit set(詳細見後文學習筆記)

test –L FILE

FILE存在並且是一個符號鏈接

test –O FILE

FILE存在並且由一個有效的USER ID所擁有

test –p FILE

FILE存在並且是一個命名管道(命名管道見後文學習筆記)

test –r FILE

FILE存在並且授予了可讀的許可權

test –s FILE

FILE存在並且size大於0

test –S FILE

FILE存在並且是一個socket

test –t FD

文件的描述符FD在終端打開

test –u FILE

FILE存在並且SUID已經被設置

test –w FILE

FILE存在並且授予了寫操作許可權

test –x FILE

FILE存在並且授予了可執行的許可權

----------------------------------------------------------------------------------------------------------------------------------------------------

expr

expr是linux的手工命令行計數器,它可以幫助我們完成一些基本的表達式值運算。同時它也是一個字元串處理工具

(1) 整數運算

$expr ARG1 | ARG2

$expr ARG1 & ARG2

$expr ARG1 < ARG2

$expr ARG1 <= ARG2

$expr ARG1 = ARG2

$expr ARG1 != ARG2

$expr ARG1 >= ARG2

$expr ARG1 > ARG2

$expr ARG1 + ARG2

$expr ARG1 – ARG2

$expr ARG1 * ARG2

使用乘法時,需要使用反斜杠進行轉義

$expr ARG1 % ARG2

(2) 字元串操作

$expr length 「xxx」 //計算字元串長度

$expr substr 「this is a」pos length //從第pos位開始截取length長度的子串

$expr index 「tesr」e //獲取e在主串中首次出現的位置

(3) 增量計數

例子

loop=3

loop=`expr $loop + 1`

echo $loop

結果是4,在第二行代碼中,使用反引號,shell會將反引號中的內容作為一個系統命令,這樣一來,就好像我們在命令行內輸入了expr $loop + 1然後這個命令的返回結果被賦值到loop。

(4) 模式匹配(按照正則表達式模式匹配串)

通過指定冒號選項計算字元串中字元數。.*意即任何字元重復0次或多次。

> VALUE=account.doc

> expr $VALUE : 』.*』

8

在expr中可以使用字元串匹配操作,這里使用模式抽取.doc文件附屬名。

$expr $VALUE : 『\(.*\).doc』

accounts

(5) 其他

+ TOKEN

將TOKEN解釋為串,不管它是一個關鍵字或者一個操作符

延伸知識:

引號的作用

1 雙引號(「」)

1)使用」」可引用除字元$(美元符號)、`(反引號)、\(反斜線)外的任意字元或字元串。雙引號不會阻止shell對這三個字元做特殊處理(標示變數名、命令替換、反斜線轉義)。

Eg:name=gezn; echo 「User name:$name」//將列印User name :gezn

Echo 「The date is:`date +date-%d-%m-%Y`」//將列印The date is: 03-05-2009

Echo –e 「$USER\t$UID」 //將列印gezn 500

2)如果要查新包含空格的字元串經常用到雙引號

2 單引號(』』)

1) 如果用單引號把字元串括起來,則dayi9nhao內字元串中的任何特殊字元的特殊含義均被屏蔽。

2) 舉例:echo –e 『$USER\t$UID』//將列印$USER $UID(沒有屏蔽\t,是因為選項「-e」的緣故)

echo 『USER\t$UID』 //將列印$USER\t$UID

3 反引號(``)

1) shell將反引號中的內容作為一個系統命令,並執行其內容。使用這種方法可以替換輸出為一個變數

2) 舉例:a=`date + date-%d-%m-%Y` //將列印The date is: 03-05-2009

4.反斜線(\)

1)如果下一個字元有特殊含義,反斜線防止shell誤解其含義,即屏蔽其特殊含義。

2)下屬字元包含有特殊含義:& * + $ ` 「 | ?

3) 在列印字元串時要加入八進制字元(ASCII相應字元)時,必須在前面加反斜線,否則shell作普通數字處。

舉例: bj=Beijing; echo 」variable\$bj=$bj」//將列印variable $bj = beijing

------------------------------------------------------------------------------------------------------------------------------------------------

Shell特殊變數

在Shell中,預先定義了幾個有特殊含義的Shell變數,它們的值只能由Shell根據實際情況進行賦值,而不能通過用戶重新設置。shell的特殊變數包括它的位置和一些系統變數.

(一)常用位置變數:

$# 命令行上實際參數的個數,但不包含Shell腳本名。
$? 上一條命令執行後的返回值(也稱作 「退出碼」)。它是一個十進制數。多數Shell命令執行成功時,則返回值為0;如果執行失敗,則返回非0值。
$$ 當前進程的進程號。
$! 上一個後台命令對應的進程號,這是一個由1~5位數字構成的數字串。
$- 由當前Shell設置的執行標志名組成的字元串。例如:
set -xv 這個命令行給Shell設置了標志-x和-v(用於跟蹤輸出)。
$* 表示在命令行中實際給出的所有實參字元串,它並不僅限於9個實參。
$@ 它與$*基本功能相同,但是使用時加引號,並在引號中返回每個參數
$0 腳本名稱
$1..$9 第N個參數

下面的aaa bbb 為變數名

${aaa:-bbb} 如果$aaa為空或未定義,則取值$bbb.否則取值$aaa

${aaa:+bbb} 如果$aaa非空,則取值$bbb,否則取值為空

${aaa:=bbb} 如果$aaa非空,則取值$aaa,否則取值$bbb而且賦值(aaa=bbb)

${aaa:3} 如果aaa=abcdefg,則${aaa:3}的值為:defg ,相當於substr,計數從0開始

${aaa:3:2} 如上; ${aaa:3:2}取值為: de.相當於substr

${#aaa} 字元串$aaa的長度.

(二)常用系統變數:
$HOME 用戶的主目錄
$USER 用戶名稱
$GROUP 用戶所屬組名
$PATH 默認的搜索路徑
$HOSTNAME 主機名稱
$TZ 時區
$MAIL 存放郵件的路徑名

練手:

#!/bin/bash

echo $0

echo $*

echo $@

echo $#

echo $$

echo $_

在terminal窗口中執行:

./test.sh -a -b –c /home

./test.sh

-a -b -c /home

-a -b -c /home

4

3250

/home

區別$*和$@編寫如下test.sh腳本:

#!/bin/bash

function testargs

{

echo "$# args"

}

testargs "$*"

testargs "$@"

unset -f testargs

在terminal窗口中執行:

./test.sh -a -b /home

1 args //很明顯就一個嘛,傳入的是$*這個串,不是解釋後的參數

3 args //$@必須和引號搭配,所以結果正確

#!/bin/bash

function testargs

{

echo "$# args"

}

testargs $*

testargs $@

unset -f testargs

再次執行有:

./test.sh -a -b /home

3 args

3 args

作者:Aga.J
出處:http://www.cnblogs.com/aga-j

Ⅸ 怎麼在linux里的mono下用C#編寫計算器功能或者記事本的功能

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
txtHidden1.Text = "";
txtHidden1.Visible = false;
txtHidden2.Text = "";
txtHidden2.Visible = false;//txtHidden1和txtHidden2的功能都是臨時存放操作符
txtTemp.Text = "";//txtTemp的功能是存放臨時結果
txtTemp.Visible = false;
txtResult.Text = "0";
txtResult.ReadOnly = true;//txtResult的功能是結果的顯示以及數字的輸入
}

private void btn0_Click(object sender, EventArgs e)//按鈕0
{
PressNumBtn(sender);
}

private void btn1_Click(object sender, EventArgs e)//按鈕1
{
PressNumBtn(sender);
}

private void btn2_Click(object sender, EventArgs e)//按鈕2
{
PressNumBtn(sender);
}

private void btn3_Click(object sender, EventArgs e)//按鈕3
{
PressNumBtn(sender);
}

private void btn4_Click(object sender, EventArgs e)//按鈕4
{
PressNumBtn(sender);
}

private void btn5_Click(object sender, EventArgs e)//按鈕5
{
PressNumBtn(sender);
}

private void btn6_Click(object sender, EventArgs e)//按鈕6
{
PressNumBtn(sender);
}

private void btn7_Click(object sender, EventArgs e)//按鈕7
{
PressNumBtn(sender);
}

private void btn8_Click(object sender, EventArgs e)//按鈕8
{
PressNumBtn(sender);
}

private void btn9_Click(object sender, EventArgs e)//按鈕9
{
PressNumBtn(sender);
}

private void btnDian_Click(object sender, EventArgs e)//按鈕小數點
{
if (txtResult.Text == "")
{
return;
}
else if (txtResult.Text.Contains("."))
{
return;
}
else
{
txtResult.Text = txtResult.Text + ".";
}
}

private void BtnJia_Click(object sender, EventArgs e)//按鈕+
{
PressOperBtn(sender);
}

private void btnJian_Click(object sender, EventArgs e)//按鈕-
{
PressOperBtn(sender);
}

private void btnCheng_Click(object sender, EventArgs e)//按鈕*
{
PressOperBtn(sender);
}

private void btnChu_Click(object sender, EventArgs e)//按鈕除
{
PressOperBtn(sender);
}

private void btnEqual_Click(object sender, EventArgs e)//按鈕=
{
if (txtHidden2.Text != "" && txtTemp.Text != "")
{
txtResult.Text = WorkOut();
}
txtHidden1.Text = "";
txtHidden2.Text = "";
txtTemp.Text = "";
}

private void btnCE_Click(object sender, EventArgs e)//按鈕清0
{
txtResult.Text = "0";
txtHidden1.Text = "";
txtHidden2.Text = "";
txtTemp.Text = "";
}

private void PressNumBtn(object sender)//操作數字鍵從0到9
{
Button btn = sender as Button;
string tag = btn.Text;
if (txtHidden1.Text == "")
{
if (txtResult.Text == "0")
{
txtResult.Text = tag;
}
else
{
txtResult.Text = txtResult.Text + tag;
}
}
else
{
txtHidden2.Text = txtHidden1.Text;
txtHidden1.Text = "";
txtResult.Text = tag;
}
}

private void PressOperBtn(object sender)//操作加、減、乘、除
{
Button btn = sender as Button;
string tag = btn.Text;
if (txtHidden2.Text != "" && txtTemp.Text != "")
{
txtResult.Text = WorkOut();
}
txtHidden1.Text = tag;
txtTemp.Text = txtResult.Text;
}

private string WorkOut()//核心功能:計算
{
string oper = txtHidden2.Text;
double num1 = Convert.ToDouble(txtTemp.Text);
double num2 = Convert.ToDouble(txtResult.Text);
double result=0;
switch (oper)
{
case "+": result = num1 + num2; break;
case "-": result = num1 - num2; break;
case "*": result = num1 * num2; break;
case "/": result = num1 / num2; break;
default: break;
}
string Result = result.ToString();
return Result;

閱讀全文

與linux命令行計算器相關的資料

熱點內容
rf3148編程器 瀏覽:505
浙江標准網路伺服器機櫃雲主機 瀏覽:587
設置網路的伺服器地址 瀏覽:600
java圖形界面設計 瀏覽:751
純前端項目怎麼部署到伺服器 瀏覽:538
瓜子臉程序員 瀏覽:505
如何保證伺服器優質 瀏覽:94
小微信aPP怎麼一下找不到了 瀏覽:299
演算法纂要學術價值 瀏覽:975
程序員你好是什麼意思 瀏覽:801
倩女幽魂老伺服器如何玩 瀏覽:561
電子鍾單片機課程設計實驗報告 瀏覽:999
看加密頻道 瀏覽:381
程序員算不算流水線工人 瀏覽:632
三星電視我的app怎麼卸載 瀏覽:44
簡述vi編譯器的基本操作 瀏覽:507
讓程序員選小號 瀏覽:91
加強數字貨幣國際信息編譯能力 瀏覽:584
購買的app會員怎麼退安卓手機 瀏覽:891
程序員的種類及名稱 瀏覽:295