在bashor 中sh,我想任何以 开头的#都是注释。
但是在bash脚本中我们写:
#!/bin/bash
Run Code Online (Sandbox Code Playgroud)
在 Python 脚本中,有:
#!/bin/python
Run Code Online (Sandbox Code Playgroud)
这是否意味着它#本身是一个评论而#!不是?
我知道两个 bash 登录脚本之间的区别:
.bashrc 仅由“非登录”shell 运行。
.bash_profile(or .bash_loginor .profile) 由“登录”shell 执行。
有没有人有一些很好的例子来说明哪些东西更适合仅登录执行,这样我只会将它们放入.bash_profile,但它们实际上没有意义.bashrc?
(我知道我们大多数源.bashrc出.bash_profile,所以似乎并没有在相反的问题多一点...)
这些是~/.profile我的 13.10 附带的股票内容(已删除注释行):
if [ -n "$BASH_VERSION" ]; then
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
Run Code Online (Sandbox Code Playgroud)
这是从 Debian 继承的,但为什么 Canonical 决定保留它?据我所知,这不是标准的 *nix 方式,我见过各种系统都没有发生这种情况,所以我认为他们一定有充分的理由这样做。这可能会导致在运行登录 shell 时出现意外行为(例如,当 ssh 进入机器时),而用户不希望有~/.bashrc来源。
我能想到的唯一好处是不要将用户与许多启动文件混淆,并允许他们.bashrc单独编辑并读取该文件,而不管 shell 类型。然而,这是一个可疑的好处,因为为登录和交互式 shell 设置不同的设置通常很有用,这会阻止您这样做。此外,登录 shell 通常不在图形环境中运行,这可能会导致错误、警告和问题(天哪!),具体取决于您在这些文件中设置的内容。
那么为什么 Ubuntu 会这样做,我错过了什么?
我正在尝试访问剪贴板,但是当我source ~/.bashrc 在终端中输入时出现此错误:
bash: /home/taran/.bashrc: line 2: syntax error near unexpected token ('
bash: /home/taran/.bashrc: line 2:alias pbpaste='xclip -selection
clipboard -o'# ~/.bashrc: executed by bash(1) for non-login shells
Run Code Online (Sandbox Code Playgroud)
我尝试在Gary Woodfine's answer to Command Line Clipboard Access 中做教程。
的输出cat ~/.bashrc是:
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- …Run Code Online (Sandbox Code Playgroud) 我是一个初学者,已经很久没有使用Linux了。现在我不再知道我做了什么,每次我打开终端都会执行 3 个命令,我不再需要这些命令,也不再像以前那样工作。现在我的问题是:如何关闭每次打开终端时执行这些命令的功能。