相关疑难解决方法(0)

从脚本本身获取Bash脚本的源目录

如何获取其中的目录路径的Bash脚本位于,里面那个脚本?

例如,假设我想使用Bash脚本作为另一个应用程序的启动器.我想将工作目录更改为Bash脚本所在的目录,因此我可以对该目录中的文件进行操作,如下所示:

$ ./application

directory bash

4672
推荐指数
44
解决办法
158万
查看次数

如何从另一个shell脚本调用shell脚本?

我有两个shell脚本,a.shb.sh.

如何b.sh从shell脚本中调用a.sh

bash shell

669
推荐指数
15
解决办法
90万
查看次数

在sh shell中找不到source命令

我有一个使用shshell 的脚本.我在使用该source命令的行中出错.它似乎source没有包含在我的shshell中.

如果我明确尝试source从shell 运行我得到:

sh: 1: source: not found
Run Code Online (Sandbox Code Playgroud)

我应该以某种方式安装"源"?我的版本有错sh吗?

bash shell sh

123
推荐指数
7
解决办法
19万
查看次数

如何从shell调用.bashrc中定义的函数?

在我的.bashrc中,我有一个名为hello的函数:

function hello() {
   echo "Hello, $1!"
}
Run Code Online (Sandbox Code Playgroud)

我希望能够从shell调用hello(),如下所示:

$ hello Lloyd
Run Code Online (Sandbox Code Playgroud)

得到输出:

> Hello, Lloyd!
Run Code Online (Sandbox Code Playgroud)

有什么诀窍?

(当然,我想到的真正功能更复杂.)

编辑:这真的是由函数中的语法错误引起的,我想!:(

function coolness() {

    if[ [-z "$1"] -o [-z "$2"] ]; then
        echo "Usage: $0 [sub_package] [endpoint]";
        exit 1;
    fi
        echo "Hi!"
}
Run Code Online (Sandbox Code Playgroud)

bash shell function

55
推荐指数
5
解决办法
7万
查看次数

从另一个shell脚本只调用一个函数

cat global_features_script.sh

.child1_script.sh
.child2_script.sh

    function svn_credentials
    {
        echo -n "Enter the svn username and press [ENTER]: " > /dev/tty
        read svn_username
        echo -n "Enter the svn commit message and press [ENTER]: "  > /dev/tty
        read svn_message
        echo -n "Enter your svn password and press [ENTER]: "  > /dev/tty
        read -s svn_password
    }
    if [ a == b]
    then
    echo "a is equal to be b"
    else
    echo "a is not equal to b"
    fi

    function exit_error
    {
    echo " There …
Run Code Online (Sandbox Code Playgroud)

linux bash shell inheritance function

1
推荐指数
1
解决办法
4220
查看次数

标签 统计

bash ×5

shell ×4

function ×2

directory ×1

inheritance ×1

linux ×1

sh ×1