从su的手册页:
For backward compatibility, su defaults to not change the current directory
and to only set the environment variables HOME and SHELL (plus USER and LOGNAME
if the target user is not root). It is recommended to always use the
--login option (instead of its shortcut -) to avoid side effects caused
by mixing environments.
...
-, -l, --login
Start the shell as a login shell with an environment similar to a real login:
o clears all the …Run Code Online (Sandbox Code Playgroud) 我正在研究另一个问题,当我意识到我不明白幕后发生了什么,这些/dev/fd/*文件是什么以及子进程如何打开它们时。
每次执行git pullor 时git reset,git都会重置对我所做的权限和所有权的更改。你自己看:
#!/usr/bin/env bash
rm -rf 1 2
mkdir 1
cd 1
git init
echo 1 > 1 && git add 1 && git ci -m 1
git clone . ../2
cd $_
chmod 0640 1
chgrp http 1
cd ../1
echo 12 > 1 && git ci -am 2
cd ../2
stat 1
git pull
stat 1
Run Code Online (Sandbox Code Playgroud)
输出:
$ ./1.sh 2>/dev/null | grep -F 'Access: ('
Access: (0640/-rw-r-----) Uid: ( 1000/ …Run Code Online (Sandbox Code Playgroud) 这是我偶尔在这里和那里遇到的这种烦人的行为:当您在控制台中用鼠标选择文本(即复制它)时,粘贴它,然后意识到每行末尾都有额外的空格。那是,
line 1
line 2
Run Code Online (Sandbox Code Playgroud)
代替
line 1
line 2
Run Code Online (Sandbox Code Playgroud)
所以,不仅仅是每一行末尾的一个空格。
我无法可靠地重现该问题,也找不到答案。我相信对于某些软件,它会在一段时间后才会显现出来。
但我只注意到,当我打开在同一文件中vim,从控制台第一个路口右转,然后tmux,它的作品了很好的前一种情况。并且不在后者中。考虑到TERM=xterm-256color控制台,并TERM=screen-256color在tmux我的猜想是,它与终端不这样做正确,或不使应用程序正确地去做的事情。我猜是一个相当模糊的猜想。所以,第一个问题是,“究竟是什么导致了它?”
另一个是,“我该怎么做?” 最坏的情况是文件位于远程位置。我以前在本地复制它,gedit最近用它打开。现在我应该可以选择在新控制台中打开它(因为我主要在tmux会话中工作),然后从那里复制。这可以做得更简单吗?
当我vim从tmuxwith运行时TERM=xterm-256color vim,它的行为很奇怪。就像没有绘制没有文字的背景一样。而且对我来说改变TERM变量似乎不太好(让软件认为它正在处理其他终端)。
编辑本地文件时,我通常做:!gedit %.
我希望systemctl --user enable SERVICE在登录时启动该服务,但这并没有发生。那么它应该是什么意思呢?
我的猜测如下:
echo "Generating some text" | su - -c cat >/output/file
Run Code Online (Sandbox Code Playgroud)
但是su说:
su: must be run from a terminal
Run Code Online (Sandbox Code Playgroud)
你会怎么办?
man su 说:
You can use the -- argument to separate su options from the arguments
supplied to the shell.
Run Code Online (Sandbox Code Playgroud)
man bash 说:
-- A -- signals the end of options and disables further option
processing. Any arguments after the -- are treated as filenames
and arguments. An argument of - is equivalent to --.
Run Code Online (Sandbox Code Playgroud)
那么,让我们看看:
[root ~] su - yuri -c 'echo "$*"' -- 1 2 3
2 3
[root ~] su - yuri -c 'echo "$*"' -- -- …Run Code Online (Sandbox Code Playgroud) 在服务器上wget-1.16需要 8 分钟才能完成:
$ wget http://http.debian.net/debian/dists/stable/Release -O -
--2017-06-12 23:44:40-- http://http.debian.net/debian/dists/stable/Release [4693/5569]
Resolving http.debian.net (http.debian.net)... 2001:4f8:1:c::15, 2605:bc80:3010:b00:0:deb:166:202, 2001:610:1908:b000::148:14, ...
Connecting to http.debian.net (http.debian.net)|2001:4f8:1:c::15|:80... failed: Connection timed out.
Connecting to http.debian.net (http.debian.net)|2605:bc80:3010:b00:0:deb:166:202|:80... failed: Connection timed out.
Connecting to http.debian.net (http.debian.net)|2001:610:1908:b000::148:14|:80... failed: Connection timed out.
Connecting to http.debian.net (http.debian.net)|140.211.166.202|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://cdn-fastly.deb.debian.org/debian/dists/stable/Release [following]
--2017-06-12 23:51:02-- http://cdn-fastly.deb.debian.org/debian/dists/stable/Release
Resolving cdn-fastly.deb.debian.org (cdn-fastly.deb.debian.org)... 2a04:4e42:3::204, 151.101.12.204
Connecting to cdn-fastly.deb.debian.org (cdn-fastly.deb.debian.org)|2a04:4e42:3::204|:80... failed: Connection timed out.
Connecting to cdn-fastly.deb.debian.org (cdn-fastly.deb.debian.org)|151.101.12.204|:80... …Run Code Online (Sandbox Code Playgroud) 考虑以下范围:1,/pattern/. 如果模式在第一行匹配,则整个文件的范围匹配:
$ cat 1.sh
#!/usr/bin/env bash
set -eu
seq 1 4 | sed -rn '1,/'"$1"'/p'
$ ./1.sh 1
1
2
3
4
$ ./1.sh 2
1
2
Run Code Online (Sandbox Code Playgroud)
你会怎么做?
UPD这是我所做的(以防万一):
re='/1/'
seq 1 4 | sed -rn "1{$re{p;q}}; 1,${re}p"
Run Code Online (Sandbox Code Playgroud)
或者这样:
seq 1 4 | sed -rn "1{/1/{p;q}}; 1,//p"
Run Code Online (Sandbox Code Playgroud) 我正在尝试php-5.3在 Arch Linux上安装,但bison太新了,所以我bison从源代码构建了旧版本。并且它似乎/usr/local默认安装到其中。(这是某种约定吗?)所以我现在想知道我是否可以安装多个版本的bisonie,与默认系统一个版本和我刚刚安装的一个版本并排安装。这类东西可能很少需要。我只是对它很好奇。这是一件很难的事吗?我该怎么办?
shell ×3
su ×3
bash ×2
arch-linux ×1
clipboard ×1
curl ×1
git ×1
ipv4 ×1
ipv6 ×1
linux ×1
options ×1
permissions ×1
sed ×1
shell-script ×1
systemd ×1
terminal ×1
tmux ×1
vim ×1
wget ×1
whitespace ×1