命名这个有点棘手......
基本上我有一个程序,它在 STDOUT 上运行时会打印一组 shell 变量:
$ ./settings
SETTING_ONE="this is setting one"
SETTING_TWO="This is the second setting"
ANOTHER_SETTING="This is another setting".
Run Code Online (Sandbox Code Playgroud)
我想从 shell 脚本中运行它,就好像 STDOUT 是用source.
我想做一些像......
source `./settings`
Run Code Online (Sandbox Code Playgroud)
......但这当然行不通。
我知道我可以这样做:
./settings >/tmp/file
source /tmp/file
Run Code Online (Sandbox Code Playgroud)
但我真的不想那样做。
有什么线索吗?
每当我sudo su从我的正常zsh(使用oh-my-zsh框架)运行时,sh默认情况下我被迫使用旧的 Bourne shell ( )(显然;这是大多数 *nix 类系统上的标准行为)。如果我在运行后zsh从内部sh运行sudo su,我会得到 Z shell,但没有 oh-my-zsh 的改进。
有没有办法将shellsudo su启动更改为zsh?如果是这样,是否也可以zsh使用oh-my-zsh?
我使用的是 OS X 10.8.4。
我只需要使用纯 sh shell 来计算字符串的长度。发生的事情/bin/sh实际上是到 bash 或其他 shell 的软链接。因此${#STRING}给出字符串的长度,因为它是高级 bash 功能。
有人能告诉我如何找到字符串的长度吗?我使用的是 Solaris 5.10 Sparc 架构
我只是运行一个工作(假设 foo.sh)。
./foo.sh
[Press Ctrl-Z to stop]
bg # enter background
Run Code Online (Sandbox Code Playgroud)
它生成输出到 stdout 和 stderr。有什么方法可以重定向到 stdout 和 stderr 到其他文件而不是当前屏幕?
我想知道是否有一种方法可以在 bash 中完成类似于 cmd.exe 上的行为的旋转样式完成,我发现它可以加快我输入命令的速度
我喜欢将我的许多环境变量定义放在.profile脚本中。如果我使用的是 POSIX 兼容的交互式 shell,比如 bash,我可以使用 source 命令从.profile更新时重新导出环境变量,而无需打开新的终端窗口。有没有办法在我使用时做同样的事情fish,它使用不同的语法来导出变量?我可以告诉fish 运行一个子sh进程并重新导出它定义的任何变量吗?
当我尝试做显而易见sh .profile的事情时,环境变量显然只在子sh进程中定义,而不会在父fish进程中更新。
编辑:定义我的变量的 shell 代码是这个
CAML_LD_LIBRARY_PATH="/home/hugo/.opam/4.01.0/lib/stublibs"; export CAML_LD_LIBRARY_PATH;
PERL5LIB="/home/hugo/.opam/4.01.0/lib/perl5:"; export PERL5LIB;
OCAML_TOPLEVEL_PATH="/home/hugo/.opam/4.01.0/lib/toplevel"; export OCAML_TOPLEVEL_PATH;
MANPATH=":/home/hugo/.opam/4.01.0/man"; export MANPATH;
PATH="/home/hugo/.opam/4.01.0/bin:/home/hugo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"; export PATH;
Run Code Online (Sandbox Code Playgroud)
不幸的是,此代码是由另一个程序自动生成的,因此也必须使用自动过程来转换为 Fish。我尝试使用以下 sed 脚本
sed 's/\(.*\)="\(.*\)".*/set -x \1 \'\2\';/'
Run Code Online (Sandbox Code Playgroud)
输出以下鱼代码
set -x CAML_LD_LIBRARY_PATH '/home/hugo/.opam/4.01.0/lib/stublibs';
set -x PERL5LIB '/home/hugo/.opam/4.01.0/lib/perl5:';
set -x OCAML_TOPLEVEL_PATH '/home/hugo/.opam/4.01.0/lib/toplevel';
set -x MANPATH ':/home/hugo/.opam/4.01.0/man';
set -x PATH '/home/hugo/.opam/4.01.0/bin:/home/hugo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games';
Run Code Online (Sandbox Code Playgroud)
我可以使用 eval 和()替换来运行
eval (my-sed-script) …Run Code Online (Sandbox Code Playgroud) bash4.3 # pwd
/bin
bash4.3 # ll sh
lrwxrwxrwx. 1 root root 4 May 17 22:22 sh -> bash
bash4.3 # ll bash
-rwxr-xr-x. 1 root root 1072056 May 17 22:22 bash
bash4.3 # bash
bash4.3 # sh
sh-4.3#
Run Code Online (Sandbox Code Playgroud)
我的操作系统是 fedora 24(默认 GNOME 版本)。
从例子中我们可以知道: 下/bin,bash是一个二进制可执行文件;sh是一个软链接bash。
因此,据我所知,type bash and press enter应该产生与type sh and press enter.
当 I 时type bash and press enter,我得到[root@localhost bin]#了预期的结果。
但是,如果我 …
如何使用标准或 GNU shell 工具获取文本文件的内容,除了最后(例如)2 行?(bash、tail、cat 等等。)
有时,当我简单地输入一个有效的命令,比如“find ...”,或者其他任何东西时,我会得到以下内容,这是完全出乎意料和令人困惑的(...我输入的是命令名称):
sh: $'\302\211...': command not found
Run Code Online (Sandbox Code Playgroud)
我认为有一些腐败正在发生。我不在我的提示中使用颜色,我在 POSIX 模式下使用 Bash shell 作为sh( chshto/bin/sh等等 - $SHELLis sh)。
这是怎么回事,为什么这种情况一直在发生?有什么我可以调试的吗?我认为这xterm不仅仅是一个问题sh,或者至少是两者的结合。
我的/etc/profile,与 Arch Linux x86-64 一起分发的:
# /etc/profile
#Set our umask
umask 022
# Set our default path
PATH="/usr/local/sbin:/usr/local/bin:/usr/bin"
export PATH
# Load profiles from /etc/profile.d
if test -d /etc/profile.d/; then
for profile in /etc/profile.d/*.sh; do
test -r "$profile" && . "$profile"
done
unset profile
fi
# …Run Code Online (Sandbox Code Playgroud) 我正在使用大学远程 Linux 帐户,遗憾的是默认 shellcsh没有选项卡完成。如何将我帐户的默认 shell 更改为bash?chsh不可用。