English 中文(简体)
- ——
原标题:Shell script not evaluating argument proceeded by --

我正在撰写一份剪辑,或者更具体地说,我应该说,“ZSH”功能,我会利用各种简短的指挥来检查像储存库等物品的状况。

然而,我与某个具体指挥机构有许多麻烦。 在另一批中流中,我发现,指挥局要打印一个盖特存放处的根fold:

git rev-parse --show-top-level

在我的实际情况中,如果我执行的话,

$(git rev-parse --show-top-level)

适当价值均已退还,所有价值都很好。 然而,我手稿中的这种做法并没有很好地发挥作用。 我只字不提:

[ $(git status &>/dev/null) $? -eq "0" ] && {
    git_name=$("git rev-parse --show-top-level")
    echo $(eval $git_name)
}

现在我不了解你的情况,但在我看来,这似乎就是这样做的wrong(不是第一行;我完全赞成这一点)。 产出大致如下:

command not found: git rev-parse --show-top-level

我似乎应该写的是:

[ $(git status &>/dev/null) $? -eq "0" ] && {
    git_name=$(git rev-parse --show-top-level)
    echo $git_name
}

产出如下:

--show-top-level

离职身份为0。

My question is, why do neither of these work, and what would be the correct way to implement this? My guess is it has something to do with there being a double-dashed argument after a space, and the last long argument is being treated as a command itself (at least in the second example), but that s the extent of my intuition.

帮助!

最佳回答

引证:

[ $(git status &>/dev/null) $? -eq "0" ] && {
    git_name=$(git rev-parse --show-toplevel)
    echo $(eval $git_name)
}

<代码>git rev-parse上的双重引用是不必要的,这一论点应当为-show-toplevel,而不是--show-top-level

问题回答

暂无回答




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签