我有一个脚本launch.sh,它作为另一个用户执行,以便创建具有正确所有者的文件。如果最初传递给脚本,我想将 -x 传递给此调用
if [ `whoami` == "deployuser" ]; then
... bunch of commands that need files to be created as deployuser
else
echo "Respawning myself as the deployment user... #Inception"
echo "Called with: <$BASH_ARGV>, <$BASH_EXECUTION_STRING>, <$->"
sudo -u deployuser -H bash $0 "$@" # How to pass -x here if it was passed to the script initially?
fi
Run Code Online (Sandbox Code Playgroud)
我已经阅读了bash 调试页面,但似乎没有明确的选项可以说明原始脚本是否使用-x.
我有一个 bash 脚本,它调用各种命令并打印一些输出(来自被调用的命令本身,例如git pull,以及脚本本身生成的信息性消息,例如Operation took XX minutes.
我想整个输出捕获到文件,从脚本本身:基本上我试图避免需要调用./myscript.sh | tee file.txt的非相关,在这里的原因。
基本上我想做这样的事情:
startCapture
git pull
echo "Text"
other-command
endCapture
Run Code Online (Sandbox Code Playgroud)
我还要求在脚本运行时将输出打印在我的 shell 上。
最终目标是:
./myscript.sh无需额外的 shell 结构即可运行这甚至可能吗?
我有一个本地和一个远程主机,都运行 Ubuntu,外壳设置为 bash。在我的主目录中,我有两个文件file-1和file-2,分别位于本地主机和名为remote. 每个主目录中还有一些其他文件,我只想列出匹配file-*.
在本地,这些会产生预期的结果file-1 file-2:
$ ls file-*
$ bash -c 'ls file-*'
Run Code Online (Sandbox Code Playgroud)
但是这些命令会返回我的远程主目录中的所有文件。那里发生什么事了?
$ ssh remote bash -c 'ls file-*'
$ ssh remote bash -c 'ls "file-*"'
$ ssh remote bash -c 'ls file-\*'
$ ssh remote bash -c 'ls "file-\*"'
Run Code Online (Sandbox Code Playgroud)
我知道这只会ssh remote 'ls file-*'产生预期的结果,但为什么ssh remote bash -c 'ls ...'似乎放弃了传递给 的参数ls ...?(我还通过管道从远程执行的 ls 输出,它被传递了,所以ls似乎只有 ls受到影响:ssh remote bash -c 'ls …
我想下载一个通过 读取一些配置参数的配置脚本read,然后执行它:
curl http://example.com/provisioning.sh | sh
Run Code Online (Sandbox Code Playgroud)
问题是,read脚本中的命令是使用-i参数调用以提供默认值:
read -p "Name: " -i joe name
echo $name
Run Code Online (Sandbox Code Playgroud)
如果我下载脚本,设置+x权限并运行它,一切都很好。
如果我用cat provisioning.sh | sh或运行它sh provisioning.sh,它会失败:
read: Illegal option -i
Run Code Online (Sandbox Code Playgroud)
如果通过 sh 运行,为什么不读取支持提供默认值?
但无论如何,我会删除-i, 剩下的
read -p "Name: " name
echo $name
Run Code Online (Sandbox Code Playgroud)
现在,如果我通过 运行脚本cat provisioning.sh | sh,它不会做任何事情。这是为什么?
Ubuntu 14.04。
我有一个 Windows diff 工具,它比我找到的任何 Linux diff 工具都要好(我已经对可视化 diff 工具做了一些相当广泛的分析)。我想在 Linux 上使用该工具(通过 Wine)并且能够将 Linux 文件路径传递给它,部分原因是像 Double Commander 这样的双窗格文件管理器在调用 diff 工具时会自动传递完整的文件路径。
所以我问这个问题的反面:如何将 Linux 样式的文件路径(包括空格等转义字符)转换为通过 Wine 运行的 Windows 工具可接受的 Windows 样式文件路径?
举个简单的例子,
输入:
/path/to/file1.ext /path/to/file2.ext
输出
"\path\to\file1.ext" "\path\to\file2.ext"
当然,在现实世界中,文件可以有空格等等,所以我正在寻找一种比bash我目前所拥有的替代更可靠的解决方案:
#!/bin/bash
p1=$1
p2=$2
wine /utils/wincmp.exe ${p1//\//\\} ${p2//\//\\}
Run Code Online (Sandbox Code Playgroud) 无论远程 IP 或端口如何,如何强制特定应用程序发起的 TCP 流量通过 SOCKS 代理?
VPN 将通过接口(通常)引导主机上的所有出站流量tun0,因此这是一种矫枉过正的解决方案。但是在拆分隧道配置中,VPN 客户端不是默认执行此操作,而是为特定应用程序提供 SOCKS 代理。虽然浏览器支持通过 SOCKS 代理进行连接,但许多其他应用程序不支持。
我试过dante socksify,但它不适用于像curl和 之类的常见程序wget。(我已经向他们的邮件列表发送了一条消息,但它没有归档到任何地方,所以我无法链接到它。)
在我的 Ubuntu 20 桌面上,我计划gedit从现在开始运行一分钟,但没有任何反应。这是为什么?
$ echo "echo foo > at.sux" | at now + 1
warning: commands will be executed using /bin/sh
job 8 at Tue Jun 2 21:47:00 2020
$ echo `which gedit` | at now + 1
warning: commands will be executed using /bin/sh
job 9 at Tue Jun 2 21:47:00 2020
$ atq
9 Tue Jun 2 21:47:00 2020 a dandv
8 Tue Jun 2 21:47:00 2020 a dandv
# A minute later
$ cat …Run Code Online (Sandbox Code Playgroud) bash ×4
shell-script ×2
application ×1
at ×1
debugging ×1
files ×1
output ×1
proxy ×1
read ×1
shell ×1
socks5-proxy ×1
ssh ×1
string ×1
wildcards ×1
wine ×1