- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我在理解 Linux 中的行为时遇到了一个简单的问题。简而言之,在 Linux 上,如果我从“桌面快捷方式”调用我的 sh 脚本,则该脚本无法看到最新的环境变量(在 bashrc 中设置)。所以我想知道这个 shell 脚本位于什么范围内?
创建测试用例并重现:
创建一个简单的 shell 脚本“testme.sh”:
!/bin/shecho "Hi This is a test script checking the env var";echo "TESTVAR = $TESTVAR";read inecho "Done";
为上面的脚本创建一个桌面快捷方式。
cd ~/Desktopvi mytest-desktop.desktop //Contents for mytest-desktop.desktop are : [Desktop Entry]Version=1.0Type=ApplicationName=TestAbhishekExec=/home/abhishek/test/hello.shTerminal=true
export TESTVAR=test_this_variable
打开一个全新的终端并使用它的完整路径(如“~/testme.sh”)执行脚本//这可以从 .bashrc 文件中看到变量“TESTVAR”的值。
现在,只需双击并执行桌面快捷方式。//这应该打开一个终端并将“TESTVAR”的值打印为空白。//所以我的问题是,这个快捷方式打开的终端的父级是谁?
我已经在 RHL 上试过了。我正在为这个问题寻找解决方案或 w/a,希望有人能尽快提供帮助。
谢谢,阿比舍克。
最佳答案
请参阅 bash 联机帮助页的 INVOCATION 部分。这是摘录
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
长话短说,如果您希望非交互式 shell 设置某些 ENV 变量,则将它们放在 ~/.bash_profile
而不是 ~/.bashrc
关于linux - 从桌面快捷方式调用 shell 脚本时未读取 .bashrc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4477328/
我想在 ~/.bashrc 文件中添加自定义别名并设置一些环境变量。我的问题是我是否需要引用系统范围的/etc/文件以确保我在该文件中完成了所有其他设置?我在尝试解决这个问题时发现的一些示例 .bas
看来我们会放 source ~/.bashrc 无论如何在我们的 .bash_profile 中。那么,为什么不只使用一个文件,比如 .bashrc 呢? 最佳答案 因为可能有些事情你每次登录只想做一
我使用的是 Ubuntu 16.04。在我的 $HOME/.profile 中,它有 echo `date` ':.profile executed starts' >> /tmp/testtmp.t
我想把我的点文件放在 GitHub 上,但我不希望公开显示我的所有别名。所以我的计划是将我的别名放在一个单独的文件中并 .gitignore 它。但是,当我尝试获取该文件时,我的权限被拒绝了。 bas
irb(main):001:0> require 'benchmark' => true irb(main):002:0> puts Benchmark.measure { system "xclip
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 11 年前。 Improve th
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我正在尝试使用 .bashrc 为 Linux 上的 JDK 设置 JAVA_HOME 和路径(通过 this 教程): 第一步: $ nano .bashrc [按回车] 第二步: export J
我有几个项目在做。我宁愿在导航到该特定目录时设置别名,而不是为每个项目的位置设置别名。每个项目都是一个 git 存储库,我已经有了一种机制,可以在导航到它时将当前分支名称附加到 $PS1。 在我的 .
我在工作和家中都从终端进行了大量开发。什么是让我的所有 .bashrc、.vimrc、.screenrc、Irssi 配置和脚本等在多台机器上同步的好解决方案? 我正在考虑在我的 .bash_logi
这可能是一个无聊的问题,但我无法找到我完全理解以下查询的答案。 我搬到了一个新的研究所,我正在访问虚拟机进行研究。我想创建一个方便的 bashrc 让生活更轻松。 因此,使用以下内容编辑 ~/.bas
我已经安装了 anaconda 但还没有添加到 bashrc 中。 在终端中输入: export PATH="/home/my_pc/anaconda3/bin:$PATH" 然后是python都运行
这可能是一个无聊的问题,但我无法找到我完全理解以下查询的答案。 我搬到了一个新的研究所,我正在访问虚拟机进行研究。我想创建一个方便的 bashrc 让生活更轻松。 因此,使用以下内容编辑 ~/.bas
我已经安装了 anaconda 但还没有添加到 bashrc 中。 在终端中输入: export PATH="/home/my_pc/anaconda3/bin:$PATH" 然后是python都运行
我刚刚获得了一个访问远程服务器的帐户(不是 root),并且我试图用 zsh 替换默认的 bash。 然后尴尬的事情发生了,我在bashrc中写了类似exec zsh的东西,希望每次登录都能用zsh替
我已经搜索并找到了几个答案,但我没有成功地改变我的答案。 操作系统:Mac OS X 我的 .bashrc 内容 # Before other PATHs... PATH=${PATH}:/usr/l
我编写了一个简单的 bash 脚本,它会自动为我的 .bashrc 添加一个别名,当它完成时,我希望它能够获取 .bashrc 例如,它目前工作正常 ./addalias.sh ls 'ls -l'
我知道可能没有简单的方法可以做到这一点,但我想我可以把它放在那里。我有一个目录,其中包含与我打交道的每个客户的子目录。我希望能够在计算机的任何位置输入客户目录名称,然后切换到该目录。换句话说: /di
我有一个如下所示的 docker 文件。 launch.sh 是这个 docker 镜像的入口点。 FROM ubuntu:16.04 USER root RUN apt-get update &&
我在一个集群上工作,因为我在那里没有 sudo 权限,所以我不得不在不同的路径 ~/bin/tool_kit 上安装一个工具包。此路径现在包含以下目录:bin、include 和 lib。这可能是一个
我是一名优秀的程序员,十分优秀!