加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在一个非常愚蠢的shell中添加/减去变量

发布时间:2020-12-16 01:10:03 所属栏目:安全 来源:网络整理
导读:我正在编写一个 shell脚本,它可以在我的本地/ bin / sh上运行(在Ubuntu 13.04上使用),但是我非常需要在一个愚蠢的盒子上运行它,因为对变量的操作我得到了一个错误: $((n2 - n1 + 1)) 不起作用,我收到如下错误: syntax error: you disabled math support fo
我正在编写一个 shell脚本,它可以在我的本地/ bin / sh上运行(在Ubuntu 13.04上使用),但是我非常需要在一个愚蠢的盒子上运行它,因为对变量的操作我得到了一个错误:
$((n2 - n1 + 1))

不起作用,我收到如下错误:

syntax error: you disabled math support for $((arith)) syntax

我不太了解那里的sh,但我认为这件事是忙碌的.我怎么能在这个哑壳上做数学?

编辑小程序列表

~ # busybox --list
[
arp
ash
cat
chgrp
chmod
chown
chroot
chvt
clear
cmp
cp
cut
date
dd
deallocvt
df
dmesg
du
echo
env
false
find
freeramdisk
ftpget
ftpput
grep
gunzip
gzip
hexdump
hwclock
ifconfig
ln
losetup
ls
md5sum
mkdir
mkfifo
mknod
mkswap
more
mount
mv
nslookup
ping
ping6
ps
pwd
renice
reset
rm
rmdir
route
seq
sh
sha1sum
sha256sum
sleep
sort
swapoff
swapon
switch_root
sync
tar
taskset
tee
telnet
test
tftp
time
top
touch
true
umount
uname
uniq
uptime
usleep
vconfig
vi
wget
whoami
yes
基于seq,sort -nr和uniq -u(POSIX兼容)的问题的另一个特定解决方案(n2 – n1 1).
foo()
{
    {
        seq 1 "$2"
        seq 0 "$1"
    } 
        | sort -n 
        | uniq -u 
        | grep -n "" 
        | sort -nr 
        | { read num; echo "${num%:*}"; }
}

$foo 100 2000
1901

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读