运行一些运行Python脚本的shell脚本,当redirect到tee或文件时,我重新sortingstdout行。 例如,如果我运行shell脚本并获得输出到我的标准输出,我的输出如下所示: Line1: Starting X Line2: Output of X Line3: Starting Y Line4: Output of Y 但是,如果我运行相同的脚本并将输出redirect到文件,或者使用tee,那么将会在执行结束时打印来自底层Python脚本的打印语句。 Line1: Output of X Line2: Output of Y Line3: Starting X Line4: Starting Y 有什么我可以做,以避免这一点?
我有一个文件模板,将被shell脚本用来生成其他文件,只是使用variables来更改此文件模板中的填充信息。 文件template.example.log内容: server name: $HOSTNAME current user: $USER 我尝试不同的方式来做这个作品。 文件log.sh内容: 1)不起作用,输出文件some_log_1.log与template.example.log相同,variables不变。 FILE_TEMPLATE="`cat template.example.log`" cat > some_log_1.log <<EOF $FILE_TEMPLATE EOF 2)也不要使用echo命令,与上面发生的一样。 echo $FILE_TEMPLATE > some_log_1.log 但如果我这样做,它的作品! cat > some_log_1.log <<EOF server name: $HOSTNAME current user: $USER EOF 输出是正确的! server name: ubuntu-server current user: leafar 但我不希望脚本以这种方式运行。 我想读取一个文本文件的内容,并将其embedded到另一个文本文件中并fill the variables 。 我怎样才能做到这一点? 谢谢。 诗:对我弱的英语感到抱歉
当我迷恋我的服务器(Centos5.2-Final)时,我有严重的问题它宣布: -bash: /bin/egrep: cannot execute binary file -bash: /bin/egrep: cannot execute binary file -bash: /bin/egrep: cannot execute binary file -bash: /bin/hostname: cannot execute binary file -bash: /bin/grep: cannot execute binary file -bash: /bin/grep: cannot execute binary file -bash: /bin/grep: cannot execute binary file -bash: /bin/grep: cannot execute binary file 在这个服务器上运行的apache和mysql工作正常,但是/ bin文件夹中的所有执行文件都有这个问题,其中一些不能执行(vi,uname,ps …) 有没有人遇到这个问题! 请告诉我如何解决它!
[root@localhost /]# ( ./address_to_char;cat) | ./overflow ( ./address_to_char;cat)如何在这里工作? 与./address_to_char|./overflow什么不同?
我正在写一个bash脚本,需要cd到一个目录中,但是目录名是有些dynamic的。 它始终以package- {dynamic版本}开头。 如何在bash中编写脚本? cd package-
我有一个守护进程,可以像这样从bash shell手动运行: daemon-binary –name some-name –separator '' /path/to/file 该守护程序的命令行选项应该在/etc/default/daemonnameconfiguration,如下所示: DAEMON_OPTS="–name some-name –separator '' /path/to/file" 这个configuration来自于一个启动守护进程的初始化脚本,它传递了DAEMON_OPTS的命令行选项,如下所示: daemon-binary "$DAEMON_OPTS" 结果是,string''被再次引用,而不是一个空stringdaemon-binary得到通过两个单一的。 所以实际上结果和调用一样: daemon-binary –name some-name –separator "''" /path/to/file 据我了解,bash在每个DAEMON_OPTS分割DAEMON_OPTS ,然后引用所有的块并将它们传递给daemon-binary 。 有没有什么办法可以写出bashvariablesDAEMON_OPTS这样当前被扩展为"''"将被扩展为一个空string?
我使用Centos 6.3并使用以下命令定制了我的.bash_profile以帮助完成历史logging(并着色提示): bind '"\e[A": history-search-backward' bind '"\e[B": history-search-forward' bind '"show-all-if-ambiguous on"' bind '"set completion-ignore-case on"' export PS1="[\[\e[32;1m\]\u@\h \[\e[33;1m\]\W\[\]]\[\e[37;1m\]\$ " [ -z "$PS1" ] && return shopt -s checkwinsize 现在,在命令提示符下,当我input任何带有“s”字符的单词时,在按空格键或继续input之前,我看不到字符。 我该如何解决这个问题?
我希望这个脚本的输出是电子邮件的主体,但我不想将它redirect到一个文件,然后到一个电子邮件,基本上没有外部login/输出文件 – 所有的行动应该在脚本内完成本身 – 是否有可能做到这一点? 例: #!/bin/bash email() { echo "Results:" } for i in $(ls -1 test); do if [ -f "test/$i" ]; then echo "'$i' it's a file." else echo "'$i' it's a directory." fi done email | mail -s "Test" [email protected] 输出: $ ./tmp.sh 'd1' it's a directory. 'f1' it's a file.
我想创build一个bash脚本foo.sh. 运行时,会提示input目录。 用户将能够使用选项卡自动完成? 这里是一些假设读取有一些选项的示例代码。 echo -n "Enter the directory of awesomeness: " read –enable-autocomplete DIR_OF_AWESOMENESS echo "The Dir of Awesomeness is $DIR_OF_AWESOMENESS" 谢谢!
为什么下面的代码总是输出“0”? #!/bin/bash RETVAL=0 echo -e '1\n2' | while read number; do RETVAL=1 done echo $RETVAL