使用 ssh,可以很容易地使用打印文件的内容
ssh host 'cat file.txt'
Run Code Online (Sandbox Code Playgroud)
禁用 ssh 且仅启用 SFTP 时,运行上一个命令会出现以下错误:
此服务仅允许 sftp 连接。
为了解决这个问题,我可以使用scp
or创建一个临时文件sshfs
(如下所示),但这看起来真的很难看。禁用 SSH 时打印远程文件内容的正确方法是什么?
mkdir tmpdir
sshfs host: tmpdir
cat tmpdir/file.txt
fusermount -u tmpdir
# This does not work! scp -v host:file.txt . shows
# "Sink: This service allows sftp connections only."
scp host:file.txt .
cat file.txt
rm file.txt
Run Code Online (Sandbox Code Playgroud) 我想创建一个 bash 完成脚本,它识别表单--arg
和--some-arg=file
.
阅读本教程和 中的一些示例后/usr/share/bash_completion/completions/
,我编写了以下脚本(以节省使用 Chromium 键入一些标志的时间):
_chromium()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Some interesting options
opts="
--disable-web-security
--easy-off-store-extension-install
--incognito
--load-extension=
--pack-extension=
--pack-extension-key=
--user-data-dir=
"
# Handle --xxxxxx=file
if [[ ${cur} == "--"*"=" ]] ; then
# Removed failures (is my logic OK?)
return 0
fi
# Handle other options
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi …
Run Code Online (Sandbox Code Playgroud)