有没有什么聪明的方法通过ssh在远程主机上运行本地Bash函数? 例如: #!/bin/bash #Definition of the function f () { ls -l; } #I want to use the function locally f #Execution of the function on the remote machine. ssh user@host f #Reuse of the same function on another machine. ssh user@host2 f 是的,我知道这是行不通的,但有没有办法做到这一点?
我试图插入一个bash heredoc里面的variables: var=$1 sudo tee "/path/to/outfile" > /dev/null << "EOF" Some text that contains my $var EOF 这不工作,因为我所期望的($ var是字面上处理,不扩大)。 我需要使用sudo tee,因为创build文件需要sudo。 做的事情如: sudo cat > /path/to/outfile <<EOT my text… EOT 不起作用,因为> outfile在当前shell中打开文件,而不是使用sudo。
我想写一个脚本来列出给定的variables的目录。 但是,在将我的input读入variablesPATH后,我根本无法运行ls 。 #!/system/bin/sh echo "enter directory for listing" read "PATH" ls "$PATH" -R > list.txt 这退出: ls: not found …并且什么都不list.txt 。
我的脚本中有echo问题: echo -n "Some string…" 版画 -n Some string… 并移动到下一行。 在控制台中,它正常工作,没有换行符: Some string…
这个 STR="Hello\nWorld" echo $STR 产生作为输出 Hello\nWorld 代替 Hello World 我应该怎么做一个string换行符? 注意: 这个问题不是关于回声 。 我知道echo -e ,但我正在寻找一种解决scheme,允许将string(包括换行符)作为parameter passing给其他没有类似选项的命令来将\n作为换行符来解释。
我有我的PHP脚本文件在/var/www/html/dbsync/index.php 。 当cd /var/www/html/dbsync/并运行php index.php它可以正常工作。 我想通过sh文件调用PHP文件,SH文件的位置如下 /var/www/html/dbsync/dbsync.sh 这是dbsync.sh文件的内容是: /usr/bin/php /var/www/html/dbsync/index.php >> /var/www/html/dbsync/myscript.log 2>&1 -q -f 当我cd /var/www/html/dbsync/并运行./dbsync.sh它也可以很好地工作。 现在,如果我设置如下的crontab: 1 * * * * /var/www/html/dbsync/dbsync.sh /var/www/html/dbsync 但是,这个crontab没有按预期工作。 什么可能是错的?
我想读取一个文件并将其保存在variables中,但我需要保留该variables,而不是只打印出文件。 我该怎么做? 我已经写了这个脚本,但它不是我所需要的: #!/bin/sh while read LINE do echo $LINE done <$1 echo 11111———– echo $LINE 在我的脚本中,我可以将文件名作为参数,例如,如果文件包含“aaaa”,则会打印出以下内容: aaaa 11111—– 但是这只是将文件打印到屏幕上,我想把它保存到一个variables! 有没有一个简单的方法来做到这一点?
我遇到了一个问题,在Bash脚本中传递参数给一个命令。 poc.sh: #!/bin/bash ARGS='"hi there" test' ./swap ${ARGS} 交换: #!/bin/sh echo "${2}" "${1}" 目前的产出是: there" "hi 只改变poc.sh(因为我相信交换做我想要它正确),我怎么得到poc.sh通过“喂那里”和testing作为两个参数,与“你好”没有引号周围呢?
我试图检查一个文件是否存在,但有一个通配符。 这是我的例子: if [ -f "xorg-x11-fonts*" ]; then printf "BLAH" fi 我也尝试过没有双引号。
我有一个简单的shell脚本,我从一个工作脚本中复制。 如果我将其复制粘贴到terminal,它将起作用: if true then true fi 然而,当我用bash myscript运行脚本时,我得到各种语法错误,就好像一些关键字丢失一样。 myscript: line 4: syntax error near unexpected token `fi' ,就好像then不存在。 myscript: line 6: syntax error: unexpected end of file ,就好像fi不存在一样。 myscript: line 4: syntax error near unexpected token `$'\r' ..什么? 为什么在这个特定的脚本中发生这种情况,而不是在我的命令行或从我复制的脚本中?