Articles of bash

nohup不适用于铬

我正在做一个小的shell脚本,启动后启动各种程序。 我使用dialog来制作菜单,然后使用一个简单的case语句来运行所需的应用程序。 除了我最喜欢的浏览器Chromium以外,一切正常。 nohup chromium &不起作用 – 当我closuresterminal铬也closures。 这是我的脚本: selection=`dialog –menu "Choose a session:" 20 50 10 "Surfing" "" "Surfing (blank)" "" "Programming" "" "Gaming" "" "Nothing" "" –stdout` case "$selection" in "Surfing" ) nohup chromium http://www.facebook.com & nohup chromium http://www.twitter.com & nohup chromium http://reader.google.com & nohup chromium http://plus.google.com & nohup chromium http://www.youtube.com & nohup […]

Linux bash:通过软链接执行时find目标文件的完整path

当用户不直接执行文件,而是通过软链接执行文件时,如何find正在执行的原始文件的完整path。 更准确地说,假设我有/original/path/a.sh ,并且在这里指向该文件的一个软链接: ~/Desktop/link-to-a.sh 。 如果用户实际执行~/Desktop/link-to-a.sh如何在~/Desktop/link-to-a.shfind"/original/path/" ? 下面的variables保存〜/桌面/这是没有用的。 DIR="$( cd "$( dirname "$0" )" && pwd )"

在bash中使用awkvariables

我有一个awk脚本,用于获取系统中总的eth中断的数量。 #!/bin/bash FILE="/proc/interrupts" awk 'NR==1 { core_count = NF print "core count: ", core_count next } /eth/ { for (i = 2; i <= 2+core_count; i++) totals[i-2] += $i } END { print "Totals" for (i = 0; i < core_count; i++) printf("CPU%d: %d\n", i, totals[i]) } ' $FILE 在bash的最后,我有core_count和totals数组。 但是,我需要使用这些variables,如何在脚本的其余部分使用它们?换句话说,如何将它们全局化?

qsub中的别名命令

使用qusb的-V选项只能导入环境variables,而不能从.bashrc导入别名。 例如 ### in .bashrc alias ll='ls -ltr' alias la='ls -A' export PYTHONPATH=/local/python_other:$PYTHONPATH 和qsub脚本是 #!/bin/sh #$ -V echo $PYTHONPATH ls ll la 在这种情况下, echo $PYTHONPATH和ls工作正常,但ll和la给错误ll: command not found 。 那么如何在qsub中导入别名命令? OR是否有更好的alias替代方法,以便命令( ll或la )的行为类似于ls并且可以轻松导入

暂停在后台运行的bash脚本

我有一个bash脚本在后台运行,它每5秒执行一次循环。 这会影响在shell本身执行的命令。 有没有办法,我可以挂起脚本执行,直到shell不执行其他命令。 谢谢

Bash脚本运行顺序,为什么它排队读命令?

我现在很困惑。 我想要做的就是创build一个监听器函数,等待两个命令 – 事情是它应该只听每两百毫秒,忽略来自用户的其他input。 function foo() { read -sN1 _input case "${_input}" in A) echo 'Option A';; B) echo 'Option B';; esac } while true; do sleep 0.2 foo done 如果我“敲击”十次A键(或者UP键),它将写入“选项A”十次(尽pipe缓慢),而最多只有三次写入时间。 为什么 – 我该如何解决?

Bash'读行'成数组和总和

我希望有人能帮帮忙… 我已经parsing整数到一个由回车分隔的文件,如下所示: … 427562786 6834257 978539857 9742 578375 … 我想把这些放在一个数组中,然后总和。 然而,在一些热切的谷歌search之后,我只能find一个合理的方法来做到这一点,使用for循环,我很好的权限不是逐行读取文件的最好方法。 我知道在这个脚本的某个地方我需要声明这样的东西: IFS =” “ 而读线 做 arrays创造魔术在这里 完成</ tmp / file SUM = 0 而读线 做 SUM = sum数组元素魔术在这里 完成</ tmp / file printf $ SUM 请能有比我更有知识的人让我知道我失踪了什么? 谢谢。 🙂

如何限制cd参数到bash中的目录?

目前,当我CD [标签] [选项卡],Bash给我的选项,包括文件和目录。 由于CD只允许目录作为参数,给我非目录选项似乎没有提供任何优势。 我如何修改它只提供目录作为选项? 我正在使用archlinux。 $ cd re redrover.sh research/

CURL:抓住liveleakvideo

我可以使用curl来抓取video吗? 我正在使用一个网站从liveleak下载video,但它停止工作。 我需要这个我的脚本之一。 基本上这是链接: http : //www.liveleak.com/e/955_1345380192 redirect到 http://edge.liveleak.com/80281E/u/u/ll2_player_files/mp55/player.swf?config=http://www.liveleak.com/player?a=config%26item_token=955_1345380192%26embed = 1%26extra_params = 并且该conf链接包含video链接 。 每次我尝试下载它,我得到—>确保file_url,file_token或playlist_token设置! http://www.liveleak.com/player?a=config%26item_token=955_1345380192%26embed=1%26extra_params= 我到目前为止所尝试的: curl http://edge.liveleak.com/80281E/u/u/ll2_player_files/mp55/player.swf?config=http://www.liveleak.com/player?a=config%26item_token=955_1345380192%26embed=1%26extra_params= -s -L -b LCOOKIE -c LCOOKIE -o LIVE curl http://edge.liveleak.com/80281E/u/u/ll2_player_files/mp55/player.swf?config=http://www.liveleak.com/player?a=config%26item_token=955_1345380192%26embed=1%26extra_params= -I curl http://edge.liveleak.com/80281E/u/u/ll2_player_files/mp55/player.swf?config=http://www.liveleak.com/player?a=config%26item_token=955_1345380192%26embed=1%26extra_params= -v curl http://www.liveleak.com/player?a=config&item_token=955_1345380192&embed=1&extra_params= wget http://www.liveleak.com/player?a=config&item_token=955_1345380192&embed=1&extra_params= curl -A "Mozilla/5.0 (X11; U; Linux x86_64; ru; rv:1.9.2.15) Gecko/20110303 Ubuntu/10.10 (maverick) Firefox/3.6.15" http://www.liveleak.com/player?a=config&item_token=955_1345380192&embed=1&extra_params=

什么是确定在Linux上运行哪个syslog守护进程的最佳方法?

我正在编写Linux shell脚本(sh,bash或csh)来确定哪个syslog守护进程正在运行。 什么是最好的办法呢? 由于我只考虑基于RHEL和rpm的版本,所以Debian及其派生版可以忽略。