shell脚本中for循环结果echo输出重复

作者&投稿:荡拜 (若有异议请与网页底部的电邮联系)
在shell脚本的循环中加入echo用于显示循环情况会影响性能吗~

有一定的影响,但是不大,比写磁盘的消耗要小很多

定义为环境变量没有用的,环境变量只是在子进程创建的时候可以从父进程复制到子进程,它无法实现从子进程往父进程传递,也不能在子进程运行期间从父进程获得新值。

解决的办法就是不要产生子进程,改成:
while read linedo i=`echo "$line" |awk '{print $3}'` j=$[j+i] echo $jdone < test

你这段脚本的问题在于ssh执行后ssh就结束了,count和echo都是在本机执行。可以把count里的命令直接放在ssh中去执行,也不用echo "$count"了。

ssh这段可修改为:

ssh $i ". ~/.bash_profile && ls ~/Data/dbc/$ACCT_CYCLE/dat/admin/|wc -l"


1、ssh root@ip "command"即可执行远程命令
2、实例
#!/bin/sh
ACCT_CYCLE=abc
ip_list=$HOME/shell/all_hosts_2
dst_dir=$HOME/Data/dbc/$ACCT_CYCLE/dat/admin/

for ip in `cat ${ip_list}`; do
echo ${ip};
count_rst=`ssh root@${ip} "find $dst_dir -type f |wc -l"`;
echo $count_rst;
done


求常用的英文简写,不要国家之类的,社会上常见的一些!!
FO F*** Off FOAF Friend Of A Friend FTASB Faster Than A Speeding Bullet FTL Faster Than ...GTH Go To Hell GTSY Glad To See Ya GYPO Get Your Pants Off HAGO Have A Good One HAK ...ASP(Active Server Pages) :是一种基于 Windows NT 的 IIS 的服务器端的脚本编写环境。 ATLA ...

I can only imagine的中文歌词
hell like this 这种炼狱 Somebody wake me up 谁来把我从梦魇中惊醒 I don't care 我不在乎 I just wanna be yours 我只想做你的附属 I know I told you I'd never love you the way that I did again 我知道我已对你说了不再爱你 After all that you did to me 在你那样对待我后...

歌词高潮含有 fo oh baby的男声英文歌曲
You gotta help me out It's all a blur last night We need a taxi 'cause you're hung-over and I'm broke I lost my fake I'd but you lost the motel key Spare me your freakin' dirty looks Now don't play me You want to cash out and get the hell out of town Don't...

求一首英文歌,开头几句是 I don't understand what they want fo
您好:不清楚,但是好听的英文歌好多呢~~~本人学英语的推荐这些吧希望你能喜欢。听歌学英语软件,里边全是经典的英文歌曲,列表中搜索歌曲就可以,还有英文歌曲的伴奏和翻译,若是有搜索不到的歌曲可以联系主播,每首歌主播都解说过,里边的英文歌曲全部非常经典,找好歌去听歌学英语。1、Bubbly--Colbie ...

请问歌中有“baby baby baby, don't make you crazy”是什么歌?女生唱...
baby baby baby, don't make you crazy 感觉有点怪 宝贝 不要让你疯狂? 没有那么说的 如果是这个意思 也应该是 don't it make you crazy 不然就成了 或者意思是 不要让我疯狂 那给把YOU 换成 ME 你的歌词有问题啊 这样不好找的 ...

i don't care 的中文歌词?
hell like this 这种炼狱 Somebody wake me up 谁来把我从梦魇中惊醒 I don't care 我不在乎 I just wanna be yours 我只想做你的附属 I know I told you I'd never love you the way that I did again 我知道我已对你说了不再爱你 After all that you did to me 在你那样对待我后...

一首女生唱的英文歌 歌词中有even though
and never your feelings, he's chasin millions fo' sho'Uh oh (uh oh), now you bout to have his baby? (dayamn)Another wild-ass nigga that's gon' drive you crazy You got too much, mo', livin to do - I'm spittin this to you,cause you deserve more than what he ...

...那首歌和名字记不得了,只记得音译是fo luo rui da(人名) weiso(歌...
But that's how we live in my genre(但这就是我们生活中的风格)When in hell I pay rottweiler(该死我到底该什么时候该付洛威纳犬的价钱)There's only one flo, and one rida(这儿只有一个Flo先生,一个Rida先生)I'm a damn shame(该死我真够惭愧)Order more champagne, pull it ...

问几个视频中的歌曲
第一首:不好找,但是是这个版本的,视频里从第二段开始放的 Title: Gloomy March Artist: Audition Unoffical OST Original title: Just Step \/ Boom Original artist: Mobb Deep \/ Royce The 5'9"Sometimes I wish I had three different faces I'm going to court for three cases in three...

艾薇儿的Innocence和When You're Gone谁会中译英
呵,这两首也是我的最爱!Innocence天真 Waking up I see that everything is ok 睁开双眼 我发现 一切如期上演 The first time in my life and now it's so great 我的生活从未如此美好呈现 Slowing down I look around and I am so amazed 放慢脚步环顾四面 我感到惊艳 I think about the ...

商都县18769241649: shell里for循环的几种写法 -
秋豪乳疾: #从文件循环进入,注意aaa.txt每行中不能有空格,不然会有问题 for i in `cat aaa.txt` do echo $i done #数字循环 for i in `seq 1 100` do echo $i done #while,可以无视行中的空格 while read line do echo $line done < aaa.txt

商都县18769241649: 如何在python 的shell里运行for循环并且执行? -
秋豪乳疾: 就拿你这题来说吧,trainMat......这行和上行for循环空两个,而不是对齐,for循环体都是这样的,如果你用python集成开发环境(如Pycharm)是帮你自动对齐的,你按照这么写,直到for循环写完,然后按两次回车Enter,就可以执行for循环了.

商都县18769241649: shell脚本中for循环结果echo输出重复 -
秋豪乳疾: 1、ssh root@ip "command"即可执行远程命令2、实例#!/bin/sh ACCT_CYCLE=abc ip_list=$HOME/shell/all_hosts_2 dst_dir=$HOME/Data/dbc/$ACCT_CYCLE/dat/admin/ for ip in `cat ${ip_list}`; do echo ${ip}; count_rst=`ssh root@${ip} "find $dst_dir -type f |wc -l"`; echo $count_rst; done

商都县18769241649: Linux的shell脚本for循环怎么调用位置变量 -
秋豪乳疾: 1、利用$@, $#, $*参数或shift移位参数进行循环2、例1#!/bin/sh while [ $# -gt 0 ]; do echo $1 shift; done3、例2#!/bin/sh until (($#==0)); do echo $1 shift; done4、例3#!/bin/sh for x in $*;do echo $x done5、例4#!/bin/sh for x in $@;do echo $x done

商都县18769241649: shell无法执行for循环多行命令 -
秋豪乳疾: 默认的情况下,Shell脚本中的命令是串行执行的,必须等到前一条命令执行完后才执行接下来的命令.shell循环中指令正常使用也是串行的,不过可以使用后台并行执行命令的方法实现并行操作; 例如: (1)、串行实例: #!/bin/bash for(( i ...

商都县18769241649: linux中shell编程for循环问题 -
秋豪乳疾: 你的变量指定的有问题.你可以这么写: #!/bin/bash for i in $( seq 1 100 ) do echo $i done

商都县18769241649: shell里的for循环怎么写 -
秋豪乳疾: for循环的运作方式,是讲串行的元素意义取出,依序放入指定的变量中,然后重复执行含括的命令区域(在do和done 之间),直到所有元素取尽为止. 其中,串行是一些字符串的组合,彼此用$IFS所定义的分隔符(如空格符)隔开,这些字符...

商都县18769241649: shell脚本怎么写for循环 -
秋豪乳疾: for I in list; do statement done I 是变量 list是一个表格 如你可以使用一串用括号括起来的数,也可以使用 命令替换 `seq 1 15` 这个命令忘记了,, 有可能是 `seq 15` [1..15] 表示1-15的数,, statement 即要执行的语句 for I in [1..10]; do echo $I done 这段for循环的含义就是显示从1~10的所有数字

商都县18769241649: linux shell脚本:while循环中调用另一个脚本遇到exit为什么会跳出循环,且继续执行循环后的程序? -
秋豪乳疾: [root@localhost ~]# cat a.sh #! /bin/sh while true do echo "loop " #source ./b.sh exit 1 #. ./b.sh done echo "end loop" [root@localhost ~]# sh -x a.sh+ true+ echo 'loop ' loop + exit 1可以看出while也是可以exit的 不是while的错,是read的问题,exit 1是给了read,read读取不到东西结束循环...所以还会继续执行while后面的echo

商都县18769241649: shell脚本中怎么输出第二列为指定内容的所有行的信息 -
秋豪乳疾: 写个脚本,使用for循环,设一个变量i 代表的是行号,从1开始,然后每次执行加1,类似于 a=`cat file|wc -l` for (( i = 0; i < = $a; i++ )) do j = `cat file |awk "NR==$i{print}"|awk '{print $2}'` k =`cat file |awk "NR==$i{print}"` if [[ j -eq xxx ]]; then echo $k fi done 没有测 但是大概就是这么个意思.

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网