【发布时间】:2014-03-20 07:02:13
【问题描述】:
我创建了一个 shell 脚本并放在主目录中。但为了让它不可见,我在它的名字前放了一个点。我的意思是.filename.sh。现在我想通过.bashrc文件调用这个文件,这个文件也是不可见的,放在主目录中。
我试过了
sh .filename.sh 和
sh filename.sh 两者都没有成功。
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
. filename.sh #I'm trying to call this script here at the beginning of the file
# 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 setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
...
... #some more content in .bashrc file
...
每当我们在终端中打开新选项卡或窗口时,此 shell 脚本都会在终端上打印一些内容。
编辑:
我试过. .filename.sh,但它只在我们位于主目录时才有效,我的意思是(user@user$)
但它应该适用于所有目录,我的意思是无论我在哪里(例如假设我在桌面user@user:~/Desktop$),现在如果我打开一个新标签,它会显示错误。它应该可以工作,因为当我将相同的内容直接放入 .bashrc 文件而不是调用此 sh 文件时,它适用于所有目录。
【问题讨论】:
-
. filename.sh应该可以工作 -
DOT和filename.sh之间是否有空格
-
绝对是的...你能试试吗?
-
从命令行运行 .bashrc。 准确地说,您看到的错误消息是什么?如果没有错误信息,则 bash 找到并成功运行该文件。
-
. filename.sh-->. .filename.sh