正如标题所示,我在询问 .bashrc 和 /etc/profile 之间的主要区别。我所知道的是 .bashrc 是一个在登录时运行的 shell 脚本(我猜)。我也知道 /etc/profile 是在 ssh 登录或终端登录上运行的。有人可以在这里引导我朝着正确的方向前进吗?
/home/my_username/.bashrc我正在尝试使用由 crontab 执行的 shell 脚本中定义的函数。
#crontab -l
# m h dom mon dow command
* * * * * /bin/sh /home/my_username/CronTab_shell_script.sh >> /home/my_username/Desktop/file.log
Run Code Online (Sandbox Code Playgroud)
假设我将 Mounted() 函数保存在
/home/my_username/.bashrc
function mounted(){
if mount|grep $1; then
echo "mounted"
else
echo "not mounted"
fi
}
Run Code Online (Sandbox Code Playgroud)
如何从
/home/my_username/CronTab_shell_script.sh
Run Code Online (Sandbox Code Playgroud) 添加新别名后,/etc/bash.bashrc我无法使用别名,除非我通过执行reboot.
我宁愿不使用reboot,因为注销很烦人,等待 2-4 秒,然后再次登录到我的 VPS 环境。
鉴于我也不想在新窗口中使用子外壳或单独的外壳,为此,我问:
我必须reboot吗?有没有办法在不重新启动的情况下在同一个 shell 中使用别名?
我已经修改了我的 Ubuntu 17.10 系统,使其看起来像 macOS。现在我对我的终端的行为感到困惑。换行符显示不正确。这个视频展示了我的意思。
修改后的文件是~/.bashrc. 这些是该文件的新内容:
# ~/.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 $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for …Run Code Online (Sandbox Code Playgroud) 我一直在玩彩色提示,设置在.bashrc.
问题是我总是需要.bashrc 在登录后获取源。当我登录时,我可以看到文件已获取(我尝试echo "SOURCED"在文件顶部添加一个。
然而,当我登录时,彩色提示的命令永远不会运行,尽管重新采购.bashrc工作 - 颜色设置在 之后source ~/.bashrc,我很好奇这种行为的性质。
# ~/.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 $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history …Run Code Online (Sandbox Code Playgroud) 我在 Ubuntu 18.04 上安装了一些工具,显然出了点问题。
有几种现象。
第一个是Ctrl+ Alt+t不会打开一个终端。为了打开终端,我需要右键单击桌面并按“打开新终端”按钮。
此外,每当我运行一个提示问题并等待答案的脚本时,脚本就会崩溃。例如,当我运行 SQLmap 时会发生以下情况:
eliko@ubuntu:~/Desktop/Tools/sqlmap$ ./sqlmap.py -u
https://nice.app.com/forgot_password?email=rob@bob.com&key=cc
[4] 2652
eliko@ubuntu:~/Desktop/Tools/sqlmap$
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 08:46:58 /2019-12-29/
[08:46:59] [INFO] testing connection to the …Run Code Online (Sandbox Code Playgroud) 我是一名 Ubuntu 初学者。我从 USB 闪存驱动器启动 Ubuntu,并且需要编辑 .bashrc 文件,但每次关闭或重新启动计算机时,所做的编辑都会消失。是否可以永久进行编辑?
为了完全清楚,当我启动 Ubuntu 时,我选择选项“尝试 Ubuntu”而不是“安装 Ubuntu”,因为我不想对邮件硬盘进行分区。
嗨(抱歉我的英语不好)
我刚刚学习了如何使用别名永久设置特定值的键:
.bashrc
alias please='sudo'
alias go='cd'
alias destroy='rm -rf'
Run Code Online (Sandbox Code Playgroud)
它工作得很好。但后来我想,如果我可以将我最喜欢的路径(如 ~/Music)存储在 .bashrc 中以便于使用,那该多有趣。所以我这样做了:
alias please='sudo'
alias go='cd'
alias destroy='rm -rf'
alias home='~'
alias work='~/Workstation'
alias back='..'
Run Code Online (Sandbox Code Playgroud)
但它没有用。我也尝试定义这样的变量:
back='..'
但它也不起作用。
我知道我可以这样做, alias gowork='cd ~/Workstation'
但我希望能够使用我存储在许多不同命令中的路径,如下所示:
destroy work
我希望能够做这样的事情:
go back/Pictures
任何帮助将不胜感激,谢谢你们!
我试图为命令创建别名,我将别名添加到文件底部.bashrc,但是当我尝试运行时,source .bashrc我得到:
.bashrc (line 6): \'case\' builtin not inside of switch block\ncase $- in\n^\nfrom sourcing file .bashrc\nsource: Error while reading file \xe2\x80\x9c.bashrc\xe2\x80\x9d\nRun Code Online (Sandbox Code Playgroud)\n这是从第 1 行开始的代码块。6:
\n.bashrc (line 6): \'case\' builtin not inside of switch block\ncase $- in\n^\nfrom sourcing file .bashrc\nsource: Error while reading file \xe2\x80\x9c.bashrc\xe2\x80\x9d\nRun Code Online (Sandbox Code Playgroud)\n这是整个 bash 文件:
\ncase $- in\n *i*) ;;\n *) return;;\nesac\nRun Code Online (Sandbox Code Playgroud)\n对此可能有什么解决办法?
\n所以我试图设置 JAVA_HOME 变量,以及每次我想使用终端时我最终都会遇到这个错误
Command 'poweroff' is available in the following places
* /sbin/poweroff
* /usr/sbin/poweroff
The command could not be located because '/sbin:/usr/sbin' is not included in the
PATH environment variable.
This is most likely caused by the lack of administrative privileges associated with
your user account.
poweroff: command not found
Run Code Online (Sandbox Code Playgroud)
我可以用这个命令修复它:
export PATH="/usr/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)
但每次我打开新终端时,我都会再次遇到错误,我必须再次使用此命令。
如果您能提供帮助,我将不胜感激。顺便说一句我用的Ubuntu 22.04.1 LTS